# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
503505 |
2022-01-08T08:30:16 Z |
jpark |
Feast (NOI19_feast) |
C++14 |
|
117 ms |
5508 KB |
#include<iostream>
using namespace std;
int main(){
int n,k;
cin >> n >> k;
int arr[n];
int pre[n+1];
int negc = 0;
int a;
bool ans = false;
for(int x=0; x<n; x++){
cin >> a; arr[x] = a;
pre[x] = 0;
if(a<0) ++negc;
}
pre[n] = 0;
int total = 0;
if(negc==0&&!ans){
for(int x=0; x<n; x++){
total += arr[x];
}
cout << total;
ans = true;
}
if(negc==1&&!ans){
if(k>=2){
for(int x=0; x<n; x++){
if(arr[x]>0){
total += arr[x];
}
}
cout << total;
}
else{
int all = 0;
for(int x=0; x<n; x++){
all += arr[x];
}
int before,after = 0;
bool reached = false;
for(int x=0; x<n; x++){
if(arr[x]<0){
reached = true;
continue;
}
if(reached){
after += arr[x];
}
else{
before += arr[x];
}
}
total = max(all,max(before,after));
}
ans = true;
}
if(k==1&&!ans){
pre[0] = 0;
for(int x=1; x<n+1; x++){
pre[x] = pre[x-1]+arr[x-1];
}
int l,r = 0;
while(r<n){
total = max(total,pre[r]-pre[l]);
if(l==r){
++r;
continue;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
106 ms |
5340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
56 ms |
3620 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
117 ms |
5508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
106 ms |
5340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |