103742024-04-01 16:03:42MagyarKendeSZLGVásárlás (75 pont)cpp17Accepted 75/7524ms6648 KiB
// thanks to the creative genius of TomaSajt
#include <bits/stdc++.h>
using namespace std;

int main() {
	cin.tie(0), ios::sync_with_stdio(0);

    int N;
    cin >> N;
    vector<int> A(N), B(N), S(N);

    for (int& x : A) cin >> x;
    for (int& x : B) cin >> x;
    for (int i = 0; i < N; i++) S[i] = B[i] - A[i];

    int best_l = -1, best_r = -1, best_save = 0, 
        l = 0, r = 0, save = 0;

    for (; r < N; r++) {
        if (save + S[r] <= 0) {
            save = 0;
            l = r + 1;
        } else {
            save += S[r];
            if (best_save < save) {
                best_save = save;
                best_l = l;
                best_r = r;
            }
        }
    } 

    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (i < best_l || i > best_r) {
            sum += B[i];
        } else {
            sum += A[i];
        }
    }

    cout << sum;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1832 KiB
2Accepted0/013ms3060 KiB
3Accepted3/33ms2264 KiB
4Accepted4/43ms2440 KiB
5Accepted4/42ms2524 KiB
6Accepted4/43ms2552 KiB
7Accepted4/43ms2640 KiB
8Accepted3/33ms2916 KiB
9Accepted4/43ms3256 KiB
10Accepted4/43ms3232 KiB
11Accepted4/43ms3092 KiB
12Accepted5/53ms3348 KiB
13Accepted3/324ms5528 KiB
14Accepted3/324ms5780 KiB
15Accepted3/324ms5888 KiB
16Accepted3/324ms5996 KiB
17Accepted3/324ms6224 KiB
18Accepted3/324ms6032 KiB
19Accepted3/324ms6292 KiB
20Accepted3/324ms6232 KiB
21Accepted3/324ms6508 KiB
22Accepted3/319ms6380 KiB
23Accepted3/324ms6648 KiB
24Accepted3/323ms6604 KiB