Submission #1103149

#TimeUsernameProblemLanguageResultExecution timeMemory
1103149joyboy23tiFeast (NOI19_feast)C++14
41 / 100
488 ms262144 KiB
#include <bits/stdc++.h> #define int long long #define N 300005 #define pb push_back #define mod 1000000007 #define fi first #define se second #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define pii pair<int,int> #define INF 1e18 #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define FORD(i, a, b) for(int i = a; i >= b; --i) using namespace std; int n, k, a[N], pre[N], dp[5500][5500]; void proc() { cin >> n >> k; FOR(i, 1, n) cin >> a[i]; FOR(i, 1, n) pre[i] = pre[i - 1] + a[i]; FOR(i, 1, k) { int mx = -INF; FOR(j, 1, n) { mx = max(mx, dp[j - 1][i - 1] - pre[j - 1]); dp[j][i] = max(dp[j - 1][i], mx + pre[j]); } } cout << dp[n][k]; } int32_t main() { if(fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ios::sync_with_stdio(false); cin.tie(nullptr); int T; T = 1; //cin >> T; while (T--) proc(); }

Compilation message (stderr)

feast.cpp: In function 'int32_t main()':
feast.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen("test.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...