Submission #825006

#TimeUsernameProblemLanguageResultExecution timeMemory
825006nasamFeast (NOI19_feast)C++17
41 / 100
4 ms468 KiB
#include <bits/stdc++.h> #define ll long long #define FOR(i,a,b) for (int i = (a), _b = (b); i <= _b; i++) #define FOD(i,b,a) for (int i = (b), _a = (a); i >= _a; i--) #define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++) #define ALL(v) (v).begin(), (v).end() #define BIT(x, i) (((x) >> (i)) & 1) #define MASK(i) (1LL << (i)) #define CNTBIT(x) __builtin_popcount(x) #define fi first #define se second #define pb push_back #define eb emplace_back #define left ___left #define right ___right #define pii pair<int, int> #define pll pair<ll, ll> #define DEBUG(n, a) FOR (i, 1, n) cout << a[i] << ' '; cout << endl; #define lob lower_bound // >= #define upb upper_bound // > #define endl "\n" #define NAME "main" using namespace std; template<class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return true; } return false; } template<class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return true; } return false; } #define gogobruhbruh ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); } const int MOD = 1e9 + 7; void add(int &a, int b){ if ((a += b) >= MOD) a -= MOD; } int sub(int a, int b){ if ((a -= b) < 0) a += MOD; return a; } int muti(int a, int b){ return (1LL * a * b) % MOD; } int Pow(int x, int y){ int res = 1; for (; y; y >>= 1){ if (y & 1) res = muti(res, x); x = muti(x, x); } return res; } const int MAX = 2e3 + 7; const ll INF = 1e18 + 5; int num, lim; ll pre[MAX], dp[MAX], Max[MAX]; void solve(){ FOR (i, 1, num){ FOD (j, lim, 1){ maximize(dp[j], Max[j - 1] + pre[i]); maximize(Max[j], dp[j] - pre[i]); } maximize(Max[0], -pre[i]); } cout << dp[lim]; } void read(){ cin >> num >> lim; FOR (i, 1, num) cin >> pre[i], pre[i] += pre[i - 1]; } int main(){ gogobruhbruh; file("main"); int test = 1; // cin >> test; while (test--) read(), solve(); }

Compilation message (stderr)

feast.cpp: In function 'int main()':
feast.cpp:30:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:65:5: note: in expansion of macro 'file'
   65 |     file("main");
      |     ^~~~
feast.cpp:30:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 | #define  file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:65:5: note: in expansion of macro 'file'
   65 |     file("main");
      |     ^~~~
#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...