#include <bits/stdc++.h>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include "ricehub.h"
using namespace std;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
vector<ll>v;
ll money;
int n;
int getmid(int i,int size){
return i + size/2;
}
bool possible(int x){
ll cost = 0, parity = 1ll*((x-1)&1);
for(int i=1;i<=x;++i)
cost += abs(v[1+x/2]-v[i]);
if(cost<=money)return 1;
for(int i=2;i<=n-x+1;++i){
cost += v[i-1] - v[getmid(i-1,x)] + parity*(v[getmid(i,x)] - v[getmid(i-1,x)]) + v[i+x-1] - v[getmid(i,x)];
if(cost<=money)return 1;
}
return 0;
}
int besthub(int cnt, int mx, int x[], ll b)
{
v.pb(0);
for(int i=0;i<cnt;++i)v.pb(1LL*x[i]);
money = b, n = cnt;
int l = 1, r = n, ans = 1;
while(l<=r){
int md = l + (r-l+1)/2;
if(possible(md))ans = md, l = md + 1;
else r = md - 1;
}
return ans;
}
// int c[maxn];
// int main(){_
// int n,l;ll b;cin>>n>>l>>b;
// for(int i=0;i<n;++i)cin>>c[i];
// cout<<besthub(n,l,c,b)<<endl;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
296 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
304 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
216 KB |
Output is correct |
28 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
444 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
832 KB |
Output is correct |
2 |
Correct |
3 ms |
804 KB |
Output is correct |
3 |
Correct |
14 ms |
2812 KB |
Output is correct |
4 |
Correct |
17 ms |
2884 KB |
Output is correct |
5 |
Correct |
7 ms |
1404 KB |
Output is correct |
6 |
Correct |
8 ms |
1480 KB |
Output is correct |
7 |
Correct |
15 ms |
2540 KB |
Output is correct |
8 |
Correct |
14 ms |
2532 KB |
Output is correct |
9 |
Correct |
5 ms |
1432 KB |
Output is correct |
10 |
Correct |
6 ms |
1352 KB |
Output is correct |
11 |
Correct |
14 ms |
2908 KB |
Output is correct |
12 |
Correct |
14 ms |
2832 KB |
Output is correct |
13 |
Correct |
12 ms |
1460 KB |
Output is correct |
14 |
Correct |
8 ms |
1480 KB |
Output is correct |
15 |
Correct |
11 ms |
2492 KB |
Output is correct |
16 |
Correct |
10 ms |
2520 KB |
Output is correct |
17 |
Correct |
13 ms |
2756 KB |
Output is correct |
18 |
Correct |
12 ms |
2704 KB |
Output is correct |
19 |
Correct |
16 ms |
2804 KB |
Output is correct |
20 |
Correct |
12 ms |
2756 KB |
Output is correct |