Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:ac代码!In Reply To:ac代码! Posted by:mc77xy at 2020-02-12 12:36:27 > #include<iostream> > #include<cstdio> > #include<cstring> > #include<cmath> > #include<algorithm> > #include<queue> > using namespace std; > int l,p,n; > pair<int,int>pa[10005]; > bool cmp(pair<int,int> a,pair<int,int> b){ > return a.first<b.first; > } > void solve(){ > pa[n].first=l; > pa[n].second=0; > n++; > priority_queue<int>que; > int ans=0,pos=0,tank=p; > for(int i=0;i<n;i++){ > int d=pa[i].first-pos; > while(tank-d<0){ > if(que.empty()){ > puts("-1"); > return; > } > tank+=que.top(); > que.pop(); > ans++; > } > tank-=d; > pos=pa[i].first; > que.push(pa[i].second); > } > printf("%d\n",ans); > } > int main(){ > scanf("%d",&n); > for(int i=0;i<n;i++) > scanf("%d%d",&pa[i].first,&pa[i].second); > scanf("%d%d",&l,&p); > for(int i=0;i<n;i++) pa[i].first=l-pa[i].first; > sort(pa,pa+n,cmp); > solve(); > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator