Submission #558199

# Submission time Handle Problem Language Result Execution time Memory
558199 2022-05-07T03:33:13 Z ngpin04 Rice Hub (IOI11_ricehub) C++14
100 / 100
12 ms 2524 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define ALL(x) (x).begin(), (x).end() 
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
  if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
  if (a < b) {a = b; return true;} return false;
}
const int N = 1e5 + 5; 
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);

#include "ricehub.h"
//#include "grader.cpp"

long long s[N];

long long sum(int l, int r) {
    return s[r] - s[l - 1];
}

int besthub(int n, int L, int a[], long long lim) {
    s[0] = a[0];
    for (int i = 1; i < n; i++) 
        s[i] = s[i - 1] + a[i];

    int ans = 0;
    for (int r = 0, l = 0; r < n; r++) {
        while (true) {
            int mid = (l + r) >> 1;
            long long tot = 0;
            tot += sum(mid, r) - (long long) (r - mid + 1) * a[mid];
            tot += (long long) (mid - l + 1) * a[mid] - sum(l, mid);
            if (tot <= lim)
                break;
            l++; 
        }

        maxi(ans, r - l + 1);
    }
    return ans;   
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 1 ms 308 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 304 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 1 ms 360 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 12 ms 2524 KB Output is correct
4 Correct 12 ms 2468 KB Output is correct
5 Correct 6 ms 1236 KB Output is correct
6 Correct 6 ms 1212 KB Output is correct
7 Correct 10 ms 2168 KB Output is correct
8 Correct 10 ms 2152 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 5 ms 1076 KB Output is correct
11 Correct 12 ms 2456 KB Output is correct
12 Correct 12 ms 2488 KB Output is correct
13 Correct 6 ms 1236 KB Output is correct
14 Correct 9 ms 1228 KB Output is correct
15 Correct 8 ms 1856 KB Output is correct
16 Correct 10 ms 1852 KB Output is correct
17 Correct 10 ms 2260 KB Output is correct
18 Correct 10 ms 2236 KB Output is correct
19 Correct 12 ms 2352 KB Output is correct
20 Correct 11 ms 2412 KB Output is correct