Skip to content

Commit

Permalink
Merge pull request satyajitghana#71 from rahulkocheta/master
Browse files Browse the repository at this point in the history
Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) Solutions.
  • Loading branch information
satyajitghana authored Oct 13, 2019
2 parents edb2dc6 + 6f6f499 commit b42327b
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <bits/stdc++.h>

using namespace std;

int main()
{
long long n,d,e;
cin>>n>>d>>e;
long long x1,x2,y1,y2,ans1=INT_MAX,ans2=INT_MAX;
x1=n/(5*e);
while(x1!=-1)
{
y1=(n-(5*e*x1))/d;
ans1=n-(5*e*x1)-(y1*d);
ans2=min(ans1,ans2);
if(ans2==0)
{
cout<<ans2;
return 0;
}
x1--;
}
ans1=ans2;

y2=n/d;
while(y2!=-1)
{
x2=(n-(y2*d))/(5*e);
ans2=n-(5*e*x2)-(y2*d);
ans1=min(ans1,ans2);
if(ans1==0)
{
cout<<ans1;
return 0;
}
y2--;
}

cout<<ans1;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <bits/stdc++.h>

using namespace std;

int main()
{
long long b,g,n,bmax,gmax,gmin,bmin;

cin>>b>>g>>n;

bmax=min(n,b);
gmax=min(n,g);

gmin=min(n-bmax , gmax);
bmin=min(n-gmax , bmax);

cout<<min(bmax-bmin+1,gmax-gmin+1);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <bits/stdc++.h>

using namespace std;

int main()
{
long long n,l=0,r=0;
string s;
cin>>n>>s;
if(n%2!=0)
{
cout<<"No";
return 0;
}
stack<char>k;
for(int i=0;i<n;i++)
{
if((!k.empty()) && k.top()=='(' && s[i]==')')
{
k.pop();
}
else
{
k.push(s[i]);
}

if(s[i]==')')
{
l++;
}
else
{
r++;
}
}
if(l!=r)
{
cout<<"No";
return 0;
}
long cnt=0;
while(!k.empty())
{
k.pop();
cnt++;
if(cnt>2)
{
cout<<"No";
return 0;
}
}
cout<<"Yes";
return 0;
}

0 comments on commit b42327b

Please sign in to comment.