13692022-07-27 15:49:50mraronVásárlás (75 pont)cpp14Accepted 75/7561ms7100 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	int n;
	cin>>n;
	vector<ll> a(n+1), b(n+1);
	for(int i=1;i<=n;++i) cin>>a[i];
	for(int i=1;i<=n;++i) cin>>b[i];
	
	ll base=accumulate(b.begin(), b.end(), 0);
	
	ll curr=0, mx=0; //max of b[i]-a[i]
	for(int i=1;i<=n;++i) {
		curr+=b[i]-a[i];
		mx=max(mx, curr);
		
		if(curr<0) curr=0;
	}
	
	cout<<(base-mx)<<"\n";
	
	return 0;
}

SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1684 KiB
2Accepted0/029ms3348 KiB
3Accepted3/32ms2096 KiB
4Accepted4/42ms2420 KiB
5Accepted4/42ms2436 KiB
6Accepted4/42ms2512 KiB
7Accepted4/43ms2716 KiB
8Accepted3/33ms2824 KiB
9Accepted4/43ms2976 KiB
10Accepted4/43ms3084 KiB
11Accepted4/43ms3280 KiB
12Accepted5/53ms3324 KiB
13Accepted3/357ms6212 KiB
14Accepted3/357ms6276 KiB
15Accepted3/357ms6404 KiB
16Accepted3/359ms6576 KiB
17Accepted3/357ms6580 KiB
18Accepted3/357ms6536 KiB
19Accepted3/356ms6664 KiB
20Accepted3/359ms6720 KiB
21Accepted3/359ms6776 KiB
22Accepted3/341ms7100 KiB
23Accepted3/361ms7072 KiB
24Accepted3/357ms7048 KiB