Submission #1083839

#TimeUsernameProblemLanguageResultExecution timeMemory
1083839lamlamlamFeast (NOI19_feast)C++17
21 / 100
22 ms5772 KiB
#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)

feast.cpp: In function 'int main()':
feast.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
feast.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...