제출 #939776

#제출 시각아이디문제언어결과실행 시간메모리
939776LitusianoDischarging (NOI20_discharging)C++17
11 / 100
86 ms17988 KiB
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; vector<int> v(n); for(int& i : v) cin>>i; int s = v[0]; int last = 0; int mx = v[0]; for(int i = 1; i<n; i++){ if(v[i] <= mx){ s += mx; } else{ int tmp = (i-last) * (v[i]-mx) + v[i]; // keep segment int tmp1 = (n-i-1)*mx + v[i]; mx = v[i]; // cerr<<tmp<<" "<<tmp1<<" "<<last<<endl; if(tmp <= tmp1){ s+=tmp; } else{ s+=tmp1; last = i; } } } cout<<s<<endl; }
#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...