CodeForces 545DQueue (排序模拟)

【题目链接】:

【题目大意】:

有n个人,每个人都有一个等待时间,,如果对于当前的人来说总等待时间超过自己的等待时间,那么这个人就会失望,问换一下顺序,使失望的人最少,问最多有多少个人不失望。【思路】:排一下序然后加然后与当前的比较。如此。。

代码:

/* * Problem: CodeForces 545D* Running time: 46MS * Complier: G++ * Author: herongwei * Create Time: 8:20 2015/9/17 星期四*/ #include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;const int N=1e5+10;int arr[N];int main(){int t;scanf("%d",&t);for(int i=1; i<=t; ++i){scanf("%d",&arr[i]);}sort(arr+1,arr+1+t);int ans=1;int temp=arr[1];for(int i=2; i<=t; ++i){if(arr[i]>=temp){ans++;temp+=arr[i];}}printf("%d\n",ans);}

版权声明:本文为博主原创文章,未经博主允许不得转载。

停止每日在车水马龙的市井里忙碌的穿梭,

CodeForces 545DQueue (排序模拟)

相关文章:

你感兴趣的文章:

标签云: