zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    MySQL 8.0.11免安装版配置步骤
    python SQLAlchemy 中的Engine详解
    Python正则表达式指南
    Qt树形控件QTreeView使用1——节点的添加删除操作
    主流的比较流行的Python量化开源框架
    selenium的常见异常
    量化投资学习【经典指标和K线图系列】之1——指数平滑均线
    量化投资学习【经典指标和K线图系列】之4——MACD
    node 连接 mysql 报错 ER_NOT_SUPPORTED_AUTH_MODE
    Mac中安 python-ldap 出错error: command 'clang' failed with exit status 1的解决办法
  • 原文地址:https://www.cnblogs.com/hsd-/p/5733621.html
Copyright © 2011-2022 走看看