![技术分享](http://www.lydsy.com/JudgeOnline/images/1828.jpg)
标签:贪心 data span string 方差 lap while code com
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<queue> 5 const int N=1e5+10; 6 int n,m,a[N],p[N]; 7 struct node{int l,r;}e[N]; 8 bool cmp(node aa,node bb){return aa.l<bb.l;} 9 int read(){ 10 int ans=0,f=1;char c=getchar(); 11 while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1;c=getchar();} 12 while(c>=‘0‘&&c<=‘9‘){ans=ans*10+c-48;c=getchar();} 13 return ans*f; 14 } 15 std::priority_queue<int>q; 16 int main(){ 17 n=read();m=read(); 18 for(int i=1;i<=n;i++)a[i]=read(); 19 for(int i=1;i<=m;i++){ 20 int l=read(),r=read();e[i]=(node){l,r}; 21 p[l]++;p[r+1]--; 22 } 23 std::sort(e+1,e+1+m,cmp); 24 int now=0,h=1;int ans=m; 25 for(int i=1;i<=n;i++){ 26 now+=p[i]; 27 while(h<=m&&e[h].l==i)q.push(e[h].r),h++; 28 while(now>a[i]&&!q.empty()){ 29 int pp=q.top();q.pop(); 30 p[pp+1]++;now--;ans--; 31 } 32 } 33 printf("%d\n",ans); 34 return 0; 35 } 36
【bzoj1828/Usaco2010 Mar】balloc 农场分配——贪心+差分+优先队列
标签:贪心 data span string 方差 lap while code com
原文地址:http://www.cnblogs.com/JKAI/p/7662957.html