Submission #833260

#TimeUsernameProblemLanguageResultExecution timeMemory
833260kwongwengFeast (NOI19_feast)C++17
59 / 100
109 ms262144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long double ld; typedef pair<ll, ll> pll; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) #define ms memset #define pb push_back #define fi first #define se second const ll INF = 1e18; void solve(){ int n,k; cin>>n>>k; vi a(n+1); FOR(i,1,n+1) cin>>a[i]; vector<ll> s(n+1); FOR(i,1,n+1) s[i]=s[i-1]+a[i]; ll dp[n+1][k+1]; ms(dp,0,sizeof(dp)); ll f[n+1][k+1]; ms(f,0,sizeof(f)); FOR(i,1,n+1){ f[i][0]=-s[i]; f[i][0]=max(f[i][0],f[i-1][0]); FOR(j,1,k+1){ dp[i][j]=max(dp[i][j],dp[i][j-1]); dp[i][j]=max(dp[i][j],dp[i-1][j]); dp[i][j]=max(dp[i][j],s[i]+f[i-1][j-1]); f[i][j]=dp[i][j]-s[i]; if (i>1) f[i][j]=max(f[i][j],f[i-1][j]); //cout<<dp[i][j]<<" "; //cout<<f[i][j]<<" "; } //cout<<"\n"; } cout<<dp[n][k]<<"\n"; } int main(){ //MOD=MOD1; ios::sync_with_stdio(false); if (fopen("input.txt", "r")) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int TC = 1; //cin >> TC; FOR(i, 1, TC+1){ //cout << "Case #" << i << ": "; solve(); } return 0; }

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:45:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:46:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |      freopen("output.txt", "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...