Submission #138729

#TimeUsernameProblemLanguageResultExecution timeMemory
138729WongHokFong_cppSails (IOI07_sails)C++14
0 / 100
1079 ms3904 KiB
#include <iostream> #include <cstdlib> #include <algorithm> #include <queue> using namespace std; int n,h,k,height,mini,s,c; struct smg { int h,k; }f[100001]; bool cmp(smg a,smg b) { return a.h<b.h; } struct helo { int flagged,num; bool operator < (const helo a) const { if (flagged==a.flagged) return num<a.num; else return flagged>a.flagged; } }pls[100001]; priority_queue <helo> q; int main(void) { cin>>n; for (int i=1;i<=n;i++) { cin>>h>>k;height=max(h,height);f[i].h=h;f[i].k=k; } sort(f+1,f+n+1,cmp); for (int i=1;i<=height;i++) { q.push((helo){0,i}); } for (int i=1;i<=n;i++) { for (int p=1;p<=f[i].k;p++) { helo cccccc=q.top(); q.pop(); c=1;pls[c]=cccccc; while (cccccc.num>f[i].h) { //cout<<"ES"; c++; pls[c]=q.top(); cccccc=q.top(); q.pop(); } cccccc.flagged++; //cout<<cccccc.flagged<<' '; q.push(cccccc); for (int xd=1;xd<=c-1;xd++) q.push(pls[xd]); } //cout<<endl<<endl; } for (int i=1;i<=height;i++) { helo cc=q.top(); q.pop(); //cout<<cc.flagged<<' '; s+=(cc.flagged-1)*cc.flagged/2; } cout<<s; }
#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...
#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...