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 |
注意有重复数据输入,贪心过#include<iostream> #include<algorithm> #include<cstring> using namespace std; const int maxn=3000; struct node{ int l,r; }e[maxn]; int n,q,vis[maxn]; bool cmp(node a,node b){ if(a.r==b.r) return a.l<b.l; return a.r<b.r; } int main(){ cin>>n>>q; for(int i=0;i<n;i++){ cin>>e[i].l>>e[i].r; } sort(e,e+n,cmp); memset(vis,0,sizeof(vis)); int ans=0; while(q--){ int l,r; cin>>l>>r; vis[l]+=r; } for(int i=0;i<n;i++){ for(int j=e[i].l;j<=e[i].r;j++){ if(vis[j]>=1){ vis[j]--; ans++; break; } } } cout<<ans<<endl; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator