Submission #872722

#TimeUsernameProblemLanguageResultExecution timeMemory
872722vjudge1K blocks (IZhO14_blocks)C++17
0 / 100
1 ms2496 KiB
#include <bits/stdc++.h> #define FOR(i, l, r) for(int i = (l); i <= (r); i ++) #define ll long long #define MASK(j) (1LL << (j)) #define int ll using namespace std; int f[100001][101]; int a[200000]; signed main() { if(fopen("MAXK.inp", "r")) { freopen("MAXK.inp", "r", stdin); freopen("MAXK.out", "w", stdout); } if(fopen("a.inp", "r")) { freopen("a.inp", "r", stdin); freopen("a.out", "w", stdout); } int n, k; cin >> n >> k; FOR(i, 1, n) cin >> a[i]; ll mx = 0; FOR(i, 1, n) mx = max(mx, a[i]), f[i][1] = mx; FOR(j, 2, k){ stack <pair <int,int>> q; FOR(i, j, n){ ll minF = f[i - 1][j - 1]; while(q.size() && a[q.top().first] <= a[i]){ minF = min(minF, q.top().second); q.pop(); } f[i][j] = minF + a[i]; if(q.size()) f[i][j] = min(f[i][j], q.top().second + a[q.top().first]); q.push({i, minF}); } } cout << f[n][k]; }

Compilation message (stderr)

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