답안 #418216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418216 2021-06-05T08:26:56 Z dxz05 쌀 창고 (IOI11_ricehub) C++14
100 / 100
23 ms 2540 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 2e5 + 3e2;

ll pref[MAXN];

ll sum(int l, int r){
    ll res = pref[r];
    if (l) res -= pref[l - 1];
    return res;
}

int besthub(int N, int L, int X[], long long B) {
    for (int i = 0; i < N; i++){
        pref[i] = X[i];
        if (i > 0) pref[i] += pref[i - 1];
    }

    int ans = 0;
    for (int i = 0; i < N; i++){
        int l = i, r = N - 1;
        while (l <= r){
            int mid = (l + r) >> 1;

            int ind = (i + mid) / 2;
            int hub = X[ind];

            ll cost = 1ll * hub * (ind - i + 1) - sum(i, ind);
            cost += sum(ind + 1, mid) - 1ll * hub * (mid - ind);

            if (cost <= B){
                ans = max(ans, mid - i + 1);
                l = mid + 1;
            } else r = mid - 1;
        }
    }

    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 300 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 308 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 596 KB Output is correct
2 Correct 5 ms 692 KB Output is correct
3 Correct 23 ms 2540 KB Output is correct
4 Correct 21 ms 2536 KB Output is correct
5 Correct 10 ms 1228 KB Output is correct
6 Correct 9 ms 1228 KB Output is correct
7 Correct 19 ms 2248 KB Output is correct
8 Correct 20 ms 2204 KB Output is correct
9 Correct 10 ms 1100 KB Output is correct
10 Correct 12 ms 1180 KB Output is correct
11 Correct 21 ms 2512 KB Output is correct
12 Correct 22 ms 2540 KB Output is correct
13 Correct 10 ms 1276 KB Output is correct
14 Correct 10 ms 1244 KB Output is correct
15 Correct 16 ms 1868 KB Output is correct
16 Correct 18 ms 1852 KB Output is correct
17 Correct 19 ms 2232 KB Output is correct
18 Correct 19 ms 2292 KB Output is correct
19 Correct 20 ms 2420 KB Output is correct
20 Correct 20 ms 2360 KB Output is correct