Submission #1212390

#TimeUsernameProblemLanguageResultExecution timeMemory
1212390huudaiFeast (NOI19_feast)C++20
18 / 100
88 ms10832 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pii pair<int, int> #define pll pair<ll,ll> #define mp make_pair #define pb push_back #define BIT(x,i) (((x)>>(i))&1) #define MASK(i) (1LL<<(i)) template<typename T1, typename T2> bool minimize(T1 &a, T2 b) {if(a>b) a=b; else return 0; return 1;} template<typename T1, typename T2> bool maximize(T1 &a, T2 b) {if(a<b) a=b; else return 0; return 1;} #define file "task" const int maxn = 3e5 + 5; const int MOD = 1e9 + 7; const int oo = 1e9; const ll OO = 1e18; int n; int k; int a[maxn]; pll f[maxn][2]; void input(){ cin >> n >> k; for(int i = 1; i <= n; i++) cin >> a[i]; } void dp(ll m){ memset(f, -0x3f, sizeof(f)); f[0][0] = mp(0, 0); for(int i = 0; i < n; i++){ maximize(f[i + 1][0], max(f[i][0], f[i][1])); maximize(f[i + 1][1], mp(f[i][0].fi + a[i + 1] - m, f[i][0].se + 1)); maximize(f[i + 1][1], mp(f[i][1].fi + a[i + 1], f[i][1].se)); } } void proc(){ ll l = 0, r = (ll)1e15; ll ans = 0; while(l <= r){ ll m = (l + r) >> 1; dp(m); pll check = max(f[n][0], f[n][1]); if(check.se >= k){ ans = check.fi + 1LL * k * m; l = m + 1; } else r = m - 1; } cout << ans; } signed main(){ cin.tie(nullptr)->sync_with_stdio(0); cout.tie(nullptr); if(fopen(file".inp", "r")){ freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); } input(); proc(); return 0; }

Compilation message (stderr)

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