• Codeforces Round #303 (Div. 2) D 贪心


    D. Queue
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Little girl Susie went shopping with her mom and she wondered how to improve service quality.

    There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.

    Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.

    Input

    The first line contains integer n (1 ≤ n ≤ 105).

    The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces.

    Output

    Print a single number — the maximum number of not disappointed people in the queue.

    Examples
    input
    5
    15 2 1 5 3
    output
    4
    Note

    Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.

    题意:排队问题  对于某个人 当排在他前面的人的总时间大于他的预约时间时 就会失去预约

    现在任意更改序列,问最多有多少人 不会失去预约;

    题解:拍个序 贪心就可以了

    这是D题?

     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 //#include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cstdio>
    11 #include<map>
    12 #include<algorithm>
    13 #include<queue>
    14 #include<cmath>
    15 #define ll __int64
    16 #define PI acos(-1.0)
    17 #define mod 1000000007
    18 using namespace std;
    19 int n;
    20 ll a[100005];
    21 int main()
    22 {
    23     scanf("%d",&n);
    24     for(int i=1; i<=n; i++)
    25         scanf("%I64d",&a[i]);
    26     sort(a+1,a+1+n);
    27     ll exm=0;
    28     int ans=0;
    29     for(int i=1; i<=n; i++)
    30     {
    31         int j;
    32         if(a[i]>=exm)
    33         {
    34             ans++;
    35             exm+=a[i];
    36             for( j=i+1; j<=n; j++)
    37             {
    38                 if(a[j]>=exm)
    39                     break;
    40             }
    41         }
    42         i=j-1;
    43     }
    44     cout<<ans<<endl;
    45     return 0;
    46 }
  • 相关阅读:
    UI Automation
    TextBlock can't be find in DataTemplate when use Coded UI Test
    windows Phone本地化
    需要反射时使用dynamic
    npm发包流程
    mockjs介绍
    oracle job不自动执行,手动可以执行
    第一章 线性结构顺序存储结构
    Java连接MySQL数据库
    阿里云服务器部署Java开发环境JDK和mysql
  • 原文地址:https://www.cnblogs.com/hsd-/p/5733621.html
Copyright © 2020-2023  润新知