# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
289474 |
2020-09-02T16:49:24 Z |
BeanZ |
Rice Hub (IOI11_ricehub) |
C++14 |
|
27 ms |
896 KB |
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
int besthub(int r, int l, int x[], ll b){
ll lf = 1, rt = 1;
ll cur = 0, ans = 0;
while (rt < r && (cur + (x[rt] - x[0])) <= b){
cur = cur + (x[rt] - x[0]);
rt++;
}
ans = max(ans, rt - lf + 1);
//cout << cur << " " << lf << " " << rt << endl;
for (int i = 2; i <= r; i++){
cur = cur - (rt - i + 1) * (x[i - 1] - x[i - 2]);
cur = cur + (i - lf) * (x[i - 1] - x[i - 2]);
while (cur > b){
cur = cur - (x[i - 1] - x[lf - 1]);
lf++;
}
//cout << cur << " " << lf << " " << rt << endl;// << " " << cur + x[i - 1] - x[lf - 2] << " " << i << " " << x[i - 1] << endl;
//cout << get(lf, rt, i) << endl;
//cout << (x[i - 1] - x[lf - 2]) << " " << (x[rt - 1] - x[i - 1]) << " " << i << " " << lf << " " << rt << endl;
while (rt < r && (x[rt] - x[i - 1]) < (x[i - 1] - x[lf - 1])){
cur = cur + x[rt] - x[i - 1] - (x[i - 1] - x[lf - 1]);
rt++;
lf++;
}
while (lf > 1 && ((x[i - 1] - x[lf - 2]) < (x[rt - 1] - x[i - 1]))){
cur = cur + x[i - 1] - x[lf - 2] - (x[rt - 1] - x[i - 1]);
rt--;
lf--;
}
while (lf > 1 && rt < r){
ll costlf = x[i - 1] - x[lf - 2];
ll costrt = x[rt] - x[i - 1];
if ((min(costlf, costrt) + cur) > b) break;
if (costlf > costrt){
cur = cur + costrt;
rt++;
} else {
cur = cur + costlf;
lf--;
}
}
while (rt < r && (cur + x[rt] - x[i - 1]) <= b){
cur = cur + x[rt] - x[i - 1];
rt++;
}
while (lf > 1 && ((cur + x[i - 1] - x[lf - 2]) <= b)){
cur = cur + x[i - 1] - x[lf - 2];
lf--;
}
//cout << cur << " " << lf << " " << rt << endl;
//cout << get(lf, rt, i) << endl;
ans = max(ans, rt - lf + 1);
}
return ans;
}
/*
ll x[N], sum[N];
ll get(ll l, ll r, ll mid){
return (mid - l) * x[mid - 1] - (sum[mid - 1] - sum[l - 1]) + (sum[r] - sum[mid]) - (r - mid) * x[mid - 1];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("time.in", "r")){
freopen("time.in", "r", stdin);
freopen("time.out", "w", stdout);
}
ll r, l, b;
cin >> r >> l >> b;
for (int i = 1; i <= r; i++) cin >> x[i - 1], sum[i] = sum[i - 1] + x[i - 1];
ll lf = 1, rt = 1;
ll cur = 0, ans = 0;
while (rt < r && (cur + (x[rt] - x[0])) <= b){
cur = cur + (x[rt] - x[0]);
rt++;
}
ans = max(ans, rt - lf + 1);
//cout << cur << " " << lf << " " << rt << endl;
for (int i = 2; i <= r; i++){
cur = cur - (rt - i + 1) * (x[i - 1] - x[i - 2]);
cur = cur + (i - lf) * (x[i - 1] - x[i - 2]);
while (cur > b){
cur = cur - (x[i - 1] - x[lf - 1]);
lf++;
}
//cout << cur << " " << lf << " " << rt << endl;// << " " << cur + x[i - 1] - x[lf - 2] << " " << i << " " << x[i - 1] << endl;
//cout << get(lf, rt, i) << endl;
//cout << (x[i - 1] - x[lf - 2]) << " " << (x[rt - 1] - x[i - 1]) << " " << i << " " << lf << " " << rt << endl;
while (rt < r && (x[rt] - x[i - 1]) < (x[i - 1] - x[lf - 1])){
cur = cur + x[rt] - x[i - 1] - (x[i - 1] - x[lf - 1]);
rt++;
lf++;
}
while (lf > 1 && ((x[i - 1] - x[lf - 2]) < (x[rt - 1] - x[i - 1]))){
cur = cur + x[i - 1] - x[lf - 2] - (x[rt - 1] - x[i - 1]);
rt--;
lf--;
}
while (rt < r && (cur + x[rt] - x[i - 1]) <= b){
cur = cur + x[rt] - x[i - 1];
rt++;
}
//cout << cur << " " << lf << " " << rt << endl;
//cout << get(lf, rt, i) << endl;
ans = max(ans, rt - lf + 1);
}
cout << ans;
}
/*
*/
Compilation message
ricehub.cpp:117:1: warning: "/*" within comment [-Wcomment]
117 | /*
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
0 ms |
256 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
0 ms |
256 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
22 |
Correct |
1 ms |
256 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
256 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
256 KB |
Output is correct |
28 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
416 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
18 ms |
896 KB |
Output is correct |
4 |
Correct |
20 ms |
896 KB |
Output is correct |
5 |
Correct |
11 ms |
640 KB |
Output is correct |
6 |
Correct |
8 ms |
640 KB |
Output is correct |
7 |
Correct |
15 ms |
896 KB |
Output is correct |
8 |
Correct |
16 ms |
896 KB |
Output is correct |
9 |
Correct |
9 ms |
640 KB |
Output is correct |
10 |
Correct |
8 ms |
616 KB |
Output is correct |
11 |
Correct |
20 ms |
896 KB |
Output is correct |
12 |
Correct |
21 ms |
836 KB |
Output is correct |
13 |
Correct |
9 ms |
640 KB |
Output is correct |
14 |
Correct |
9 ms |
768 KB |
Output is correct |
15 |
Correct |
14 ms |
896 KB |
Output is correct |
16 |
Correct |
16 ms |
896 KB |
Output is correct |
17 |
Correct |
17 ms |
896 KB |
Output is correct |
18 |
Correct |
27 ms |
896 KB |
Output is correct |
19 |
Correct |
19 ms |
896 KB |
Output is correct |
20 |
Correct |
19 ms |
896 KB |
Output is correct |