CodeForces - 426A(排序)

Sereja and Mugs

Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that this player lost.

As soon as Sereja‘s friends heard of the game, they wanted to play it. Sereja, on the other hand, wanted to find out whether his friends can play the game in such a way that there are no losers. You are given the volumes of all mugs and the cup. Also, you know that Sereja has (n - 1)friends. Determine if Sereja‘s friends can play the game so that nobody loses.

Input

The first line contains integers n and s(2 ≤ n ≤ 100; 1 ≤ s ≤ 1000) — the number of mugs and the volume of the cup. The next line contains n integers a1a2, ..., an(1 ≤ ai ≤ 10). Number ai means the volume of the i-th mug.

Output

In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise.

Sample Input

Input

3 41 1 1

Output

YES

Input

3 43 1 3

Output

YES

Input

3 44 4 4

Output

NO

Source

Codeforces Round #243 (Div. 2)

题意:一个空杯,有n杯水,n-1个人每个人选一杯水往一个瓶子里倒水,不溢出就YES。

题解:扔掉水最多的那一杯,剩下的和如果小于等于瓶子容积就YES。

#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
using namespace std;
int a[200050];
int main()
{
    int i,n,t,c,sum=0;
    scanf("%d%d",&n,&c);
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a,a+n);
    sum-=a[n-1];
    if(sum<=c)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;

    return 0;
}
时间: 2024-10-14 11:35:14

CodeForces - 426A(排序)的相关文章

CSU-ACM2014暑假集训基础组训练赛(1) 解题报告

•Problem A HDU 4450                 水题,签到题 水题..没啥好说的.给大家签到用的. 1 #include <cstdio> 2 int main(){ 3 int n,a,ans; 4 while(scanf("%d",&n),n){ 5 ans = 0; 6 for(int i = 0;i < n;i++){ 7 scanf("%d",&a); 8 ans += a*a; 9 } 10 pr

树状数组模拟3个元素的排序 Codeforces 12D Ball

http://codeforces.com/problemset/problem/12/d Ball time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output N ladies attend the ball in the King's palace. Every lady can be described with three val

Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序+贪心

链接: http://codeforces.com/contest/822/problem/C 题意: 有x天的假期, 有n张旅行票, 每张票有起始时间l, 结束时间r, 花费cost, 想把假期分成两部分出去旅游, 两部分时间不能重合(ri < lj || rj < li), 问最小花费是多少, 如果不能两部分, 输出-1 题解: CF官方解法, 效率O(nlogn2) 设置一个结构体, struct P{int p, len, cost, type}; 将每张票(l, r, cost) 表

计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task

E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作,每次操作将(l,r)内的字符升序或降序排列,输出q次操作后的字符串. analyse: 基本思想是计数排序. 所谓计数排序,是对一个元素分布较集中的数字集群进行排序的算法,时间复杂度为O(n),但使用条件很苛刻.首先对n个数扫一遍,映射出每个数字出现的次数,然后再O(n)扫一遍处理出:对于数字ai,

CodeForces 22D Segments 排序水题

题目链接:点击打开链接 右端点升序,取右端点 暴力删边 #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <set> #include <math.h> using namespace std; #define inf 10

Codeforces 589B Layer Cake(两次排序)

题目地址:http://codeforces.com/problemset/problem/589/B 思路:设长<=宽,将各物体按长从小到大排序.从后向前枚举长,同时将宽加入并排序.则对于位置 j 的宽,有 num-j 物体宽大于它(由于长从小到大枚举,保证新加入物体的长不大于当前物体的长),则体积 a[i].r*b[j]*(num-j) 每次取最大即可. #include<cstdio> #include<cstring> #include<iostream>

Codeforces 484B Maximum Value(排序+二分)

题目链接: http://codeforces.com/problemset/problem/484/B 题意: 求a[i]%a[j] (a[i]>a[j])的余数的最大值 分析: 要求余数的最大值非常明显a[i]越接近a[j]的倍数则余数越大 ,因此我们将全部的元素从大到小排序 : 然后枚举a[j]的倍数 ,二分查找小于a[i]倍数的最大值,然后更新余数的最大值. 代码例如以下: #include <iostream> #include <cstdio> #include

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序 题意 有 a[ i ] 个数 要求选最多的数 使其和不超过 S ,且在此情况下,和最小选最多数情况下 和最小 且 每个数有加成 如果选了 k个数 那么加成后 就是 a[ i ] + k*i ; 题解 二分mid 表示选了个数 加成一下,将加成以后结果排序一下 , 若前 mid数 和大于 s 则此方案不可行 PS 要用 long long ..... 还有 co

Codeforces 439D Devu and his Brother(排序)

题目链接:Codeforces 439D  Devu and his Brother 题目大意:Devu和他的哥哥互相深爱着对方,我确信他们是搞基的,为此我还去查了一下Devu是男人名还是女人名,但是后来发现His Brother,所以可以证明,他们就是搞基的.题目很简单,父亲给了他们两个人分别一个数组.但是Devu希望自己最小的数都可以不必哥哥最大的数小,现在对数组中的数有两种操作,一种是加1,一种是减1,问最少进行几次操作可以使得两个数组满足要求. 解题思路:将两个数组合并在一起,然后排序,