제출 #1177965

#제출 시각아이디문제언어결과실행 시간메모리
1177965ndtaiDischarging (NOI20_discharging)C++20
20 / 100
100 ms8272 KiB
#include <bits/stdc++.h> #define ll long long #define all(v) v.begin(),v.end() #define MASK(i) (1LL << (i)) #define ii pair<int,int> #define fi first #define se second #define endl '\n' #define forr(i,l,r,add) for(int i = l;i <= r; i = i + add) #define fodd(i,l,r,sub) for(int i = l;i >= r ; i = i - sub) template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;} template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;} using namespace std; mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); #define rand rd long long Rand(long long l , long long h){ assert(l <= h); return l + 1ll * rd() % (h - l + 1) * (rd() % (h - l + 1)) % (h - l + 1); } //////////////////////////////////////////////////////////// end of template //////////////////////////////////////////////////////////// const int MAX = 1e6 + 5; ii a[MAX]; int n; bool cmp(ii x , ii y){ return x.fi > y.fi || (x.fi == y.fi && x.se < y.se); } void INP(){ cin >> n; forr(i , 1 , n , 1) cin >> a[i].fi , a[i].se = i; sort(a + 1 , a + 1 + n , cmp); ll res = 1ll * a[1].fi * n; int val = a[1].fi , duytri = a[1].se; int tmp = duytri; forr(i , 2 , n , 1){ //cout << a[i].fi << ' ' << a[i].se << ' ' << val << ' ' << duytri << ' ' << tmp << ' ' << res << endl; if(a[i].se > tmp) continue; ll ans = res - 1ll * val * (tmp - 1) + 1ll * a[i].fi * n; if(minimize(res , ans)) val = a[i].fi , duytri = a[i].se;minimize(tmp , a[i].se); } cout << res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define TASK "DISCHARGING" // freopen(TASK".inp" , "r" , stdin); //freopen(TASK".out" , "w" , stdout); INP(); return 0; }
#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...