NC24831. [USACO 2009 Feb G]Fair Shuttle
描述
输入描述
* Line 1: Three space-separated integers: K, N, and C
* Lines 2..K+1: Line i+1 describes group i of the cows with three space-separated integers: , , and
输出描述
* Line 1: The maximum number of cows that can ride the shuttle at the fair.
示例1
输入:
8 15 3 1 5 2 13 14 1 5 8 3 8 14 2 14 15 1 9 12 1 12 15 2 4 6 1
输出:
10
C++11(clang++ 3.9) 解法, 执行用时: 124ms, 内存消耗: 1012K, 提交时间: 2020-02-26 18:31:23
#include<bits/stdc++.h> struct act { int s,t,num; friend bool operator <(act a,act b) { if(a.t!=b.t) return a.t<b.t; return a.s<b.s; } }a[50010]; int end[111]; bool cmp(int x,int y) { return x>y; } int main() { int k,n,c; scanf("%d%d%d",&k,&n,&c); for(int i=1;i<=k;++i) scanf("%d%d%d",&a[i].s,&a[i].t,&a[i].num); std::sort(a+1,a+1+k); int sum=0; for(int i=1;i<=k;++i) { std::sort(end+1,end+1+c,cmp); for(int j=1;a[i].num&&j<=c;++j) if(end[j]<=a[i].s) { ++sum; end[j]=a[i].t; a[i].num--; } } printf("%d\n",sum); return 0; }