#include "ricehub.h"
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define v vector
typedef long long ll;
typedef pair<int, int > pii;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
ll P[100000];
#define num(a,b) ((ll)((b)-(a)+1))
#define sum(a,b) ((ll)(P[b]-(a-1<0?0:P[a-1])))
ll cost(int l, int r){
// cout << "cost "<< l << " to " << r << endl;
int m = (l+r)/2;
// cout << "m = " << m << endl;
// cout << "num(m+1,r) " << m+1 << " " << r << " " << num(m+1,r) << endl;
// printf("sum(m+1,r,%d)-num(m+1,r,%d)*sum(m,m,%d)+num(l,m,%d)*sum(m,m,%d)-sum(l,m,%d)\n", sum(m+1,r), num(m+1,r), sum(m,m), num(l,m), sum(m,m), sum(l,m));
return sum(m+1,r)-num(m+1,r)*sum(m,m)+num(l,m)*sum(m,m)-sum(l,m);
}
int besthub(int R, int L, int X[], long long B){
P[0] = X[0];
FOR(i,1,R) P[i] = X[i]+P[i-1];
int ans = 0;
for(int i = 0, j = -1; i < R; i++){
while(j+1 < R && cost(i,j+1) <= B)
j++;
assert(i<=j);
maxx(ans, j-i+1);
}
// FOR(i,0,R) cout << "x " << X[i] << endl;
// cout << "budget " << B << endl;
// FOR(i,0,R) cout << "p " << P[i] << endl;
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
380 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
380 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
372 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
380 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
504 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
6 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
8 ms |
632 KB |
Output is correct |
3 |
Correct |
23 ms |
1528 KB |
Output is correct |
4 |
Correct |
22 ms |
1528 KB |
Output is correct |
5 |
Correct |
13 ms |
888 KB |
Output is correct |
6 |
Correct |
12 ms |
892 KB |
Output is correct |
7 |
Correct |
20 ms |
1528 KB |
Output is correct |
8 |
Correct |
20 ms |
1528 KB |
Output is correct |
9 |
Correct |
11 ms |
888 KB |
Output is correct |
10 |
Correct |
12 ms |
892 KB |
Output is correct |
11 |
Correct |
24 ms |
1528 KB |
Output is correct |
12 |
Correct |
24 ms |
1784 KB |
Output is correct |
13 |
Correct |
14 ms |
888 KB |
Output is correct |
14 |
Correct |
13 ms |
888 KB |
Output is correct |
15 |
Correct |
20 ms |
1144 KB |
Output is correct |
16 |
Correct |
19 ms |
1144 KB |
Output is correct |
17 |
Correct |
22 ms |
1404 KB |
Output is correct |
18 |
Correct |
23 ms |
1400 KB |
Output is correct |
19 |
Correct |
23 ms |
1400 KB |
Output is correct |
20 |
Correct |
25 ms |
1528 KB |
Output is correct |