답안 #880562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880562 2023-11-29T16:22:19 Z AlphaMale06 쌀 창고 (IOI11_ricehub) C++14
17 / 100
12 ms 5468 KB
#include<bits/stdc++.h>
//#include "ricehub.h"

using namespace std;
using ll = long long;


int besthub(int R, int L, int X[], long long B)
{
    int c=B;
    int n=R;
    int a[n];
    if(n==1)return 1;
    for(int i=0; i< n; i++)a[i]=X[i];
    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+1)-pref[s+1]-a[s]*(n-s)+suf[s+1];
    while(cost>c){
        s=sufind/2;
        cost=a[s]*(s+1)-pref[s+1]-a[s]*(sufind-s)+suf[s]-suf[sufind];
        if(cost<=c)break;
        sufind--;
    }
    mx=sufind;
    for(int i=1; i< n; i++){
        cost=0;
        while(cost<=c && sufind<n){
            s=(sufind+i)/2;
            cost=a[s]*(s-i+1)-pref[s+1]+pref[i]-a[s]*(sufind-s)+suf[s+1]-suf[sufind+1];
            sufind++;
        }
        if(sufind==n && cost<=c){
            mx=max(mx, sufind-i);
            break;
        }
        else{
            sufind--;
            mx=max(mx, sufind-i);
        }
    }
    return mx;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 504 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 500 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 860 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Incorrect 12 ms 5468 KB Output isn't correct
4 Halted 0 ms 0 KB -