#include<bits/stdc++.h>
#include "ricehub.h"
using namespace std;
using ll = long long;
int besthub(int n, int L, int a[], long long c)
{
ll sum=0;
ll pref[n+1];
ll suf[n+1];
suf[n]=0;
pref[0]=0;
for(int i=0; i< n; i++){
sum+=a[i];
pref[i+1]=sum;
}
for(int i=n-1; i>=0; i--){
suf[i]=pref[n]-pref[i];
}
ll sufind=n;
ll mx;
ll s=n/2;
ll cost=a[s]*s-pref[s]-a[s]*(n-s)+suf[s];
while(cost>c){
sufind--;
s=sufind/2;
cost=a[s]*s-pref[s]-a[s]*(n-s)+suf[s]-suf[sufind+1];
}
mx=sufind+1;
for(int i=1; i< n; i++){
s=(sufind-i)/2;
cost=a[s]*(s-i)-pref[s]+pref[i]-a[s]*(n-sufind)+suf[sufind];
while(cost<=c && sufind<=n){
sufind++;
s=(sufind-i)/2;
cost=a[s]*(s-i+1)-pref[s+1]-pref[i]-a[s]*(n-s-1)+suf[s]-suf[sufind];
}
sufind--;
mx=max(mx, sufind-i+1);
}
return mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |