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 }
  • 相关阅读:
    【SQL Server数据迁移】32位的机器:SQL Server中查询ORACLE的数据
    ORACLE存储过程,循环语法和游标
    Oracle变量的定义、赋值及使用
    Oracle数据库常用语法
    Windows下将JAVA jar注册成windows服务
    Java压缩图片
    如何去除图片背景?这款一键抠图软件帮你
    远程办公,这 13 个工具比微信、QQ更好用
    java程序在windows后台执行的办法
    Usage of API documented as @since 1.6+……的解决办法
  • 原文地址:https://www.cnblogs.com/hsd-/p/5733621.html
Copyright © 2011-2022 走看看