제출 #1129980

#제출 시각아이디문제언어결과실행 시간메모리
1129980AliyyiakbarK개의 묶음 (IZhO14_blocks)C++20
100 / 100
139 ms79856 KiB
/* #ifndef ONLINE_JUDGE #include "AkbarKING.h" #else #define debug(...) #define debugArr(...) #define debugG(...) #endif */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define int long long #define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #define ep emplace_back #define pb push_back #define pii pair<int,int> #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() using namespace std; using namespace __gnu_pbds; template <typename T> using __indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using __indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; const int sz = 1e5+9; const int LOG = 63; const int MOD = 1e9+7; const int INF = 1e18; int a[sz],dp[105][sz], st[sz][2]; int n,m; void solve() { cin>>n>>m; for (int i = 1; i <= n; ++i) { cin>>a[i]; dp[1][i] = a[i]; if (i > 1) { dp[1][i] = max(dp[1][i],dp[1][i-1]); } } for (int i = 1; i < m; ++i) { int top = 0; for (int j = i + 1; j <= n; ++j) { int x = dp[i][j-1]; while(top && st[top][0] <= a[j]) { if (x > st[top][1]) { x = st[top][1]; } --top; } if (!top || x + a[j] < st[top][0] + st[top][1]) { st[++top][0] = a[j]; st[top][1] = x; } dp[i+1][j] = st[top][0] + st[top][1]; } } cout<<dp[m][n]<<'\n'; } signed main() { $AzH_TxdmN$ int t = 1; //cin>>t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...