103722024-04-01 15:51:57MagyarKendeSZLGVásárlás (75 pont)cpp17Time limit exceeded 39/75449ms16860 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define all(v) v.begin(), v.end()

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

    int N;
    cin >> N;
    vector<int> A(N), B(N), psA(N + 1), psB(N + 1);

    for (int& x : A) cin >> x;
    for (int& x : B) cin >> x;

    partial_sum(all(A), psA.begin() + 1);
    partial_sum(all(B), psB.begin() + 1);

    int best_i = 0, best_j = 0, best_save = INT_MIN;

    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            int costA = psA[j + 1] - psA[i];
            int costB = psB[j + 1] - psB[i];

            int save = costB - costA;

            if (best_save < save) {
                best_save = save;
                best_i = i;
                best_j = j;
            }
        }
    }

    cout << min(
        psB.back(), 
        psB[best_i] + (psA[best_j + 1] - psA[best_i]) + (psB.back() - psB[best_j + 1])
    );
}
SubtaskSumTestVerdictTimeMemory
base39/75
1Accepted0/03ms2100 KiB
2Time limit exceeded0/0400ms2768 KiB
3Accepted3/33ms2904 KiB
4Accepted4/43ms2952 KiB
5Accepted4/43ms2892 KiB
6Accepted4/43ms2900 KiB
7Accepted4/44ms3296 KiB
8Accepted3/34ms3264 KiB
9Accepted4/46ms3420 KiB
10Accepted4/46ms4024 KiB
11Accepted4/46ms3944 KiB
12Accepted5/56ms4152 KiB
13Time limit exceeded0/3400ms5696 KiB
14Time limit exceeded0/3368ms6812 KiB
15Time limit exceeded0/3370ms7880 KiB
16Time limit exceeded0/3361ms9092 KiB
17Time limit exceeded0/3449ms10308 KiB
18Time limit exceeded0/3441ms11296 KiB
19Time limit exceeded0/3370ms12192 KiB
20Time limit exceeded0/3365ms13336 KiB
21Time limit exceeded0/3381ms14348 KiB
22Time limit exceeded0/3365ms14752 KiB
23Time limit exceeded0/3416ms16140 KiB
24Time limit exceeded0/3361ms16860 KiB