18102022-12-03 20:47:30kdbVásárlás (75 pont)cpp11Accepted 75/7521ms5996 KiB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n), b(n), d(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (size_t i = 0; i < n; i++)
    {
        cin >> b[i];
        d[i] = a[i] - b[i];
    }

    int m = 0, s = 0, i = 0, j = 0;

    for (j = 0; j < n; j++) {
        s += d[j];
        if (s >= 0) {
            while (i <= j) {
                s -= d[i];
                i++;
            }
        }
        m = min(m, s);
    }

    cout << accumulate(b.begin(), b.end(), 0) + m << endl;
    return 0;
}
/*
4
5 6 7 8
10 1 2 20
*/
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1828 KiB
2Accepted0/012ms3072 KiB
3Accepted3/32ms2260 KiB
4Accepted4/42ms2456 KiB
5Accepted4/42ms2396 KiB
6Accepted4/42ms2676 KiB
7Accepted4/42ms2756 KiB
8Accepted3/32ms3044 KiB
9Accepted4/42ms3276 KiB
10Accepted4/42ms3216 KiB
11Accepted4/42ms3288 KiB
12Accepted5/52ms3364 KiB
13Accepted3/320ms5584 KiB
14Accepted3/320ms5660 KiB
15Accepted3/320ms5784 KiB
16Accepted3/320ms5820 KiB
17Accepted3/320ms5680 KiB
18Accepted3/320ms5680 KiB
19Accepted3/320ms5876 KiB
20Accepted3/320ms5804 KiB
21Accepted3/320ms5856 KiB
22Accepted3/317ms5740 KiB
23Accepted3/321ms5996 KiB
24Accepted3/320ms5888 KiB