Submission #146371

#TimeUsernameProblemLanguageResultExecution timeMemory
146371abacabaK blocks (IZhO14_blocks)C++14
0 / 100
6 ms1276 KiB
#include <iostream> #include <string> #include <cstring> #include <vector> #include <map> #include <algorithm> #include <math.h> #include <utility> #include <set> #include <time.h> #include <list> #include <typeinfo> #include <cstdio> #include <numeric> #include <stack> #include <stdio.h> using namespace std; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> const int inf = 2e9; const int N = 1e5 + 15; int n, k, a[N], dp[2][N], maxx; stack <int> s[2]; int main() { for(int i = 0; i < 2; ++i) for(int j = 0; j < N; ++j) dp[i][j] = inf; scanf("%d%d", &n, &k); for(int i = 1; i <= n; ++i) { scanf("%d", &a[i]); maxx = max(maxx, a[i]); dp[1][i] = maxx; } for(int i = 2; i <= k; ++i) for(int j = 1; j <= n; ++j) { int cur = dp[(i & 1) ^ 1][j - 1]; while(!s[0].empty() && s[0].top() < a[j]) { cur = min(cur, s[1].top()); s[0].pop(), s[1].pop(); } if(s[1].empty() || s[0].top() + s[1].top() > cur + a[j]) s[0].push(a[j]), s[1].push(cur); if(j >= i) dp[i & 1][j] = s[0].top() + s[1].top(); } printf("%d\n", dp[k & 1][n]); return 0; }

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...