「日常训练」Queue(Codeforces Round 303 Div.2 D)

简单到让人不敢相信是D题,但是还是疏忽了一点。

题意与分析 (Codeforces 545D)

题意:n人排队,当一个人排队的时间超过他需要服务的时间就会厌烦,现在要求一个最优排列使得厌烦的人最少。

思路:让服务时间长的人到后面去是一个显然的思路。那么直接排序即可。然后逐个检查,当一个人按照时间顺序排序仍然厌烦的时候,将他直接放到最后去(也就是不考虑:反正你怎么样都会厌烦,不如不为你服务2333),这样能够最大化满意的人数。

代码

#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define ZERO(x) memset((x), 0, sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define rep(i, a, b) for (repType i = (a); i <= (b); ++i)
#define per(i, a, b) for (repType i = (a); i >= (b); --i)
#define QUICKIO                  \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
using namespace std;
using ll=long long;
using repType=int;

ll nt=0;
int t[100005];
int main()
{
	int n; cin>>n;
	rep(i,1,n) cin>>t[i];
	sort(t+1,t+n+1);
	int ans=0;
	//rep(i,1,n) cout<<t[i]<<" "; cout<<endl;
	rep(i,1,n)
	{
		if(t[i]>=nt) {ans++; nt+=t[i];}
	}
	cout<<ans<<endl;
	return 0;
}
posted @ 2018-09-30 23:21  ISoLT  阅读(118)  评论(0编辑  收藏  举报