# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
198808 |
2020-01-27T18:31:25 Z |
imaxblue |
Coins (BOI06_coins) |
C++17 |
|
133 ms |
480 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vp3i vector<p3i>
#define vpll vector<pll>
#define vp3l vector<p3l>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846
#define startrng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, k, c, o, s, cnt;
vector<pii> v;
pii ans;
int32_t main(){
ans = mp(0, -1);
scanf("%i%i", &n, &k);
fox(l, n){
scanf("%i%i", &c, &o);
o=1-o;
if (c <= s){
s-=v.back().x;
cnt-=v.back().y;
v.pop_back();
s+=c;
cnt+=o;
v.pb(mp(c, o));
} else {
if (c > k) break;
ans = max(ans, mp(cnt, -s));
while(v.size() && v.back().y==0){
s-=v.back().x;
cnt-=v.back().y;
v.pop_back();
}
s+=c;
cnt+=o;
if (s > k) break;
v.pb(mp(c, o));
}
//cout << cnt << ' ' << s << endl;
}
if (s <= k){
ans = max(ans, mp(cnt, -s));
}
cout << ans.x << endl << k+ans.y;
return 0;
}
/*
7 25
1 0
2 0
3 1
5 0
10 0
13 0
20 0
*/
Compilation message
coins.cpp: In function 'int32_t main()':
coins.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &n, &k);
~~~~~^~~~~~~~~~~~~~~~
coins.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i", &c, &o);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
109 ms |
256 KB |
Output is correct |
8 |
Incorrect |
115 ms |
376 KB |
Output isn't correct |
9 |
Correct |
133 ms |
376 KB |
Output is correct |
10 |
Correct |
122 ms |
480 KB |
Output is correct |