Submission #398658

# Submission time Handle Problem Language Result Execution time Memory
398658 2021-05-04T16:50:51 Z AugustinasJucas Rice Hub (IOI11_ricehub) C++14
0 / 100
88 ms 2028 KB
#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 time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 2028 KB Output isn't correct
2 Halted 0 ms 0 KB -