HDU 5240 Exam
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest
2015ACM-ICPC上海大都会赛 签到题
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int maxn=100000+10; struct Exam { int r,e,l; int Start,End; }E[maxn]; int T,n; bool cmp(const Exam&a,const Exam&b) { return a.e<b.e; } int main() { scanf("%d",&T); for(int t=1;t<=T;t++) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d%d",&E[i].r,&E[i].e,&E[i].l); E[i].Start=E[i].e; //考试开始时间 E[i].End=E[i].e+E[i].l; //考试结束时间 } sort(E,E+n,cmp); int preEnd=0; int k=0; int ans=0; for(int i=0;i<n;i++) { int Len=E[i].Start-preEnd; while(Len) { int Min=min(E[k].r,Len); E[k].r=E[k].r-Min; Len=Len-Min; if(E[k].r==0) k++; } if(E[i].r!=0) {ans=1; break;} preEnd=E[i].End; } printf("Case #%d: ",t); if(ans) printf("NO\n"); else printf("YES\n"); } return 0; }