제출 #398662

#제출 시각아이디문제언어결과실행 시간메모리
398662AugustinasJucas쌀 창고 (IOI11_ricehub)C++14
0 / 100
3 ms460 KiB
    #include "ricehub.h"
    #pragma GCC optimize("O3")
    #include <bits/stdc++.h>
    using namespace std;
    int n, l;
    const int dydis = 1e5 + 10;
    const long long inf = 1e18;
    long long pref[dydis];
    long long sm(int l, int r){
        if(l > r) return 0;
        return pref[r] - (l == 0 ? 0ll : pref[l-1]);
    }
    int besthub(int N, int LL, int mas[], long long B) {
        n = N; l = LL;
        for(int i = 0; i < n; i++) pref[i] = 1ll * mas[i] + (i == 0 ? 0ll : pref[i-1]);
        int ans = 0;
        int L = 0; int R = 0;
        long long cur = 0;
        for(int i = 0; i < n; i++){
            if(mas[i] - mas[0] + cur > B) break;
            R = i;
            cur += abs(mas[0] - mas[i]);
        }
        ans = R - L + 1;
        for(int i = 1; i < n; i++){
            if(i > R) R = i;
            long long SR = sm(i, R) - 1ll * (R - i + 1)  * mas[i];
            long long SL = 1ll * (i - L+ 1)  * mas[i] - sm(L, i);
            long long cur = SR + SL;
     
          //  cout << "i = " << i << ", L = " << L << ", R = " << R << "cur = " << cur << endl;
            while(cur > B){
                long long jeiK = abs(mas[L] - mas[i]);
                long long jeiD = abs(mas[R] - mas[i]);
             //   cout << "L, R = " << L << "; " << R << ", cur = " << cur << endl;
                if(jeiK > jeiD){
                    cur -= jeiK;
                    L++;
                }else{
                    cur -= jeiD;
                    R--;
                }
            }
         //   cout << "po pirmo, L = " << L <<", R = " << R << ", cur = " << cur << endl;
            while(cur <= B){
                long long jeiK = (L == i ? inf : abs(mas[L-1] - mas[i]));
                long long jeiD = (R == n-1 ? inf : abs(mas[R+1] - mas[i]));
                if(min(jeiK, jeiD) + cur > B) break;
                if(jeiK < jeiD){
                    L--;
                    cur += jeiK;
                }else{
                    R++;
                    cur += jeiD;
                }
            }
        //    cout << "i = " << i << ", L = " << L << ", R = " << R << "cur = " << cur << endl<<endl;
            ans = max(ans, R - L + 1);
        }
        return ans;
    }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...