87512024-01-28 17:30:55IgnácVásárlás (75 pont)cpp17Accepted 75/7561ms5960 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

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

	int sum = 0, sum2 = 0, min1 = 0, max2 = INT_MIN, min1i = 0, max2i = 0, max2min1i = 0;
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		sum2 += b[i];
		sum += b[i] - a[i];
		if (sum < min1) {
			min1 = sum;
			min1i = i;
		}
		if (sum - min1 > max2) {
			max2 = sum - min1;
			max2i = i;
			max2min1i = min1i;
		}
	}

	cout << sum2 - max2;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1812 KiB
2Accepted0/030ms2760 KiB
3Accepted3/33ms2412 KiB
4Accepted4/43ms2664 KiB
5Accepted4/43ms2752 KiB
6Accepted4/43ms3000 KiB
7Accepted4/43ms3324 KiB
8Accepted3/33ms3228 KiB
9Accepted4/44ms3324 KiB
10Accepted4/44ms3540 KiB
11Accepted4/44ms3620 KiB
12Accepted5/54ms3724 KiB
13Accepted3/359ms5172 KiB
14Accepted3/359ms5208 KiB
15Accepted3/359ms5296 KiB
16Accepted3/359ms5288 KiB
17Accepted3/359ms5296 KiB
18Accepted3/359ms5424 KiB
19Accepted3/357ms5504 KiB
20Accepted3/359ms5512 KiB
21Accepted3/359ms5600 KiB
22Accepted3/341ms5688 KiB
23Accepted3/361ms5960 KiB
24Accepted3/357ms5676 KiB