#include <bits/stdc++.h>
#include "ricehub.h"
#define ll long long
#define vi vector<ll>
#define ii pair<ll, ll>
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define P 31
#define mod 1'000'000'007
#define inf 1'000'000'000'000'000'0
#define pb push_back
#define str string
#define sz(x) (x).size()
#define vvi vector<vi>
#define fun function
#define oopt cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
#define file freopen("problemname.in", "r", stdin); freopen("pr.out", "w", stdout);
#define dbg(v) cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;
using namespace std;
template <class T, int SZ> using arr = array<T, SZ>;
int besthub(int r, int l, int x[], long long b)
{
vi kum(r+1);
vi kum1(r+1);
for (ll i = 1; i <= r; i++)
kum[i] = kum[i-1]+x[i-1];
for (ll i = r-1; i >= 0; i--)
kum1[i] = kum1[i+1]+l-x[i];
deque<ll> dq;
ll rez = 0;
auto calcprice = [&dq, &kum, &kum1, &x, &l]()
{
ll med = dq[dq.size()/2];
int std = dq.size()-dq.size()/2-1;
int stl = dq.size()/2;
ll tr = kum[dq.back()+1]-kum[med+1]-x[med]*std;
tr = tr+kum1[dq[0]]-kum1[med]-(l-x[med])*stl;
return tr;
};
for (ll i = 0; i < r; i++)
{
dq.pb(i);
ll trc = calcprice();
while (trc > b)
{
dq.pop_front();
trc = calcprice();
}
rez = max(rez, (ll)dq.size());
}
return rez;
}
// #include <stdio.h>
// #include <stdlib.h>
// #define MAX_R 1000000
// static int R, L;
// static long long B;
// static int X[MAX_R];
// static int solution;
// inline
// void my_assert(int e) {if (!e) abort();}
// static void read_input()
// {
// int i;
// my_assert(3==scanf("%d %d %lld",&R,&L,&B));
// for(i=0; i<R; i++)
// my_assert(1==scanf("%d",&X[i]));
// my_assert(1==scanf("%d",&solution));
// }
// int main()
// {
// int ans;
// read_input();
// ans = besthub(R,L,X,B);
// if(ans==solution)
// printf("Correct.\n");
// else
// printf("Incorrect. Returned %d instead of %d.\n",ans,solution);
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
452 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
488 KB |
Output is correct |
24 |
Correct |
1 ms |
592 KB |
Output is correct |
25 |
Correct |
1 ms |
592 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
2 ms |
592 KB |
Output is correct |
28 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
848 KB |
Output is correct |
2 |
Correct |
4 ms |
848 KB |
Output is correct |
3 |
Correct |
13 ms |
5968 KB |
Output is correct |
4 |
Incorrect |
14 ms |
5456 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |