当前位置:Gxlcms > 数据库问题 > Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E. Buy Low Sell High [贪心 II][数据结构 I]

Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E. Buy Low Sell High [贪心 II][数据结构 I]

时间:2021-07-01 10:21:17 帮助过:18人阅读

pii pair<int, int> #define mod 1000000007 #define mp make_pair #define pi acos(-1) #define eps 0.00000001 #define mst(a,i) memset(a,i,sizeof(a)) #define all(n) n.begin(),n.end() #define lson(x) ((x<<1)) #define rson(x) ((x<<1)|1) #define inf 0x3f3f3f3f typedef long long ll; typedef unsigned long long ull; using namespace std; const int maxn = 3e5+5; priority_queue<pii,vector<pii>,greater<pii>>a; int has[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int i, j, k, m, n; cin>>n; ll ans =0; for(int i= 1;i<=n;++i) { cin>>k; a.push(mp(k,i)); if(a.top().first>=k)continue; ans+=k-a.top().first; if(!has[a.top().second]) { a.pop(); has[i]=1; } else{ has[a.top().second]=0; has[i]=1; } } cout<<ans<<endl; return 0; }

 

Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E. Buy Low Sell High [贪心 II][数据结构 I]

标签:cond   直接   else   pre   false   code   include   namespace   force   

人气教程排行