Submission #198786

#TimeUsernameProblemLanguageResultExecution timeMemory
198786red1108Candies (JOI18_candies)C++17
100 / 100
492 ms17656 KiB
#include<bits/stdc++.h> #include<ext/rope> using namespace std; using namespace __gnu_cxx; #define fi first #define se second #define fastio ios_base::sync_with_stdio(false);cin.tie(0) #define fopen freopen("input.txt", "r", stdin) #define eb emplace_back #define em emplace #define prec(a) cout<<fixed;cout.precision(a); #define all(a) (a).begin(), (a).end() typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef tuple<int,int,int> tiii; const ll INF = 2e16; const int inf = 2e9; ll in[200010],ans; int n,l[200010],r[200010]; set<pll> SET; int main(){ fastio; cin>>n; for(int i=1;i<=n;i++){ cin>>in[i]; SET.insert(pll(-in[i],i)); l[i]=i-1;r[i]=i+1; } r[0]=1; l[n+1]=n; for(int j=1;j<=(n+1)/2;j++){ pll t = pll(SET.begin()->fi, SET.begin()->se); SET.erase(t); ans -= t.fi; int i = t.se; if(l[i]!=0&&r[i]!=n+1) in[i] = max(in[r[i]] + in[l[i]] - in[i],-INF); else in[i] = -INF; SET.insert(pll(-in[i], i)); SET.erase(pll(-in[l[i]],l[i])); SET.erase(pll(-in[r[i]],r[i])); l[i] = l[l[i]]; r[i] = r[r[i]]; r[l[i]] = i; l[r[i]] = i; cout<<ans<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...