# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1083839 | lamlamlam | Feast (NOI19_feast) | C++17 | 22 ms | 5772 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
struct node
{
int pre_max,pre_min,suf_max,suf_min,best,worst;
};
node rev(node x)
{
x.pre_max *= -1;
x.pre_min *= -1;
x.suf_max *= -1;
x.suf_min *= -1;
x.best *= -1;
x.worst *= -1;
swap(x.pre_max,x.pre_min);
swap(x.suf_max,x.suf_min);
swap(x.best,x.worst);
return x;
}
const int MN = 3e5+5,inf = 1e18;
int n,k,a[MN],pre[MN];
void sub34()
{
int l,r,cur_max,res = 0;
while(k--){
for(int i=1; i<=n; i++) pre[i] = a[i] + pre[i-1];
cur_max = 0;
for(int i=1; i<=n; i++){
for(int j=i; j<=n; j++){
if(pre[j]-pre[i-1] > cur_max){
cur_max = pre[j] - pre[i-1];
l = i;
r = j;
}
}
}
if(cur_max==0) break;
for(int i=l; i<=r; i++) res += a[i],a[i] = -a[i];
}
cout << res;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#define task "sus"
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin >> n >> k;
for(int i=1; i<=n; i++) cin >> a[i];
if(n<=300) return sub34(),0;
cerr << "\nTime: " << clock();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |