Submission #1328945

#TimeUsernameProblemLanguageResultExecution timeMemory
1328945santi3223Feast (NOI19_feast)C++20
30 / 100
94 ms2756 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<ll>
#define ff(aa, bb, cc) for(ll aa = bb; aa < cc; aa++)
#define pb push_back
#define all(aaa) aaa.begin(), aaa.end()
#define rall(aaa) aaa.rbegin(), aaa.rend()
#define pll pair<ll, ll>
#define fi first
#define se second
#define ed "\n"

int main(){
	ll n, k;
	cin >> n >> k;
	vl arr(n);
	ll c = 0, maxx = 0, cur = 0, minn = LLONG_MAX;
	ff(i, 0, n){
		cin >> arr[i];
		c += arr[i];
		cur += arr[i];
		if(cur < 0) cur = 0;
		maxx = max(maxx, cur);
		minn = min(minn, arr[i]);
	}
	maxx = max(maxx, cur);
	if(k == n || minn >= 0){ cout << c; return 0;}
	if(k == 1){ cout << maxx; return 0;}
	if(minn < 0) cout << c-minn;
	
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...