基本算法2-2/3-1
先按右端点排序再按左端点排序
记录一个空座位的数组$q[]$
每次有新的牛上车之后,对$q$重新排序
贪心的让牛能上就上,显然优
code
1 #include <bits/stdc++.h> 2 using namespace std; 3 namespace gengyf{ 4 #define ll long long 5 const int maxn=1e5+10; 6 const int mod=1e9; 7 inline int read(){ 8 int f=1,x=0;char s=getchar(); 9 while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();} 10 while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();} 11 return f*x; 12 } 13 int q[maxn]; 14 int n,k,c,ans; 15 struct node{ 16 int l,r,m; 17 }a[maxn]; 18 bool cmp(node x,node y){ 19 return x.r==y.r?x.l>y.l:x.r<y.r; 20 } 21 bool cmp2(int x,int y){ 22 return x>y; 23 } 24 int main(){ 25 k=read();n=read();c=read(); 26 for(int i=1;i<=k;i++){ 27 a[i].l=read();a[i].r=read();a[i].m=read(); 28 } 29 sort(a+1,a+1+k,cmp); 30 for(int i=1;i<=k;i++){ 31 sort(q+1,q+1+c,cmp2); 32 for(int j=1;j<=c&&a[i].m;j++){ 33 if(q[j]<=a[i].l){ 34 ans++;q[j]=a[i].r;a[i].m--; 35 } 36 } 37 } 38 printf("%d",ans); 39 return 0; 40 } 41 } 42 signed main(){ 43 gengyf::main(); 44 return 0; 45 }