QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#340131#1808. Efficient PartitioningHKOI0#WA 1ms7740kbC++14990b2024-02-28 15:54:282024-02-28 15:54:30

Judging History

你现在查看的是最新测评结果

  • [2024-02-28 15:54:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7740kb
  • [2024-02-28 15:54:28]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;

const int N = 2e5 + 11;
int a[N], b[N], c[N], p[N];
int n; 


bool ok(int C){
    int cmin = b[0];
    for (int i = 1; i <= n; i++) {
        if (c[i] + p[i] >= C - cmin) {
            cmin = max(cmin, b[i] - p[i]);
            if (i == n) return true;
        }
    }
    return false;
}

void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) p[i + 1] = p[i] + a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) cin >> c[i];

    int l = 0, r = 1LL << 60;
    while (l != r) {
        int mid = (l + r + 1) / 2;
        if (ok(mid)) l = mid;
        else r = mid - 1;
    }
    cout << l << '\n';
}

int32_t main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int T = 1;
    // cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7656kb

input:

2
1 -1
-1 4
1 -2

output:

1

result:

ok answer is '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 7720kb

input:

1
1000000000
1000000000
1000000000

output:

3000000000

result:

ok answer is '3000000000'

Test #3:

score: 0
Accepted
time: 1ms
memory: 7740kb

input:

11
-323225375 -897098227 -795978453 501188072 409939326 -362890219 969123048 962633819 252457646 694824070 -406990840
-696821643 -663750226 -570551722 670541392 172964990 399404695 -305728788 -157617655 -801518744 -328729631 -160335217
-465411342 -660775657 515997870 -34787742 628368976 84800619 -72...

output:

91174984

result:

ok answer is '91174984'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7644kb

input:

2
12 3
-13 -1
-19 7

output:

9

result:

ok answer is '9'

Test #5:

score: 0
Accepted
time: 1ms
memory: 7656kb

input:

9
-13 -10 18 4 -9 8 -12 18 1
3 3 7 10 -16 -10 8 -7 -19
-20 15 -17 2 7 15 11 14 8

output:

16

result:

ok answer is '16'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 7736kb

input:

10
-3 -20 -13 19 -12 2 -15 -9 -12 -15
8 20 8 19 9 -13 8 16 10 8
12 8 7 14 -1 -11 -7 -6 4 -7

output:

0

result:

wrong answer expected '-14', found '0'