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 4
1 1 1
Output
YES
Input
3 4
3 1 3
Output
YES
Input
3 4
4 4 4
Output
NO

Source

题意:一个空杯,有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[];
int main()
{
int i,n,t,c,sum=;
scanf("%d%d",&n,&c);
for(i=;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
sort(a,a+n);
sum-=a[n-];
if(sum<=c)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl; return ;
}

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

  1. Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题

    题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...

  2. 2017年暑假ACM集训日志

    20170710: hdu1074,hdu1087,hdu1114,hdu1159,hdu1160,hdu1171,hdu1176,hdu1010,hdu1203 20170711: hdu1231, ...

  3. Codeforces Round #292 (Div. 1) B. Drazil and Tiles 拓扑排序

    B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a f ...

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

    E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...

  5. Codeforces 588E. A Simple Task (线段树+计数排序思想)

    题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...

  6. Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp排序

    B. Maximum Submatrix 2 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  7. Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 离散化拓扑排序

    C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem ...

  8. Codeforces 599C Day at the Beach(想法题,排序)

    C. Day at the Beach One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunate ...

  9. Educational Codeforces Round 1 C. Nearest vectors 极角排序

    Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/ ...

随机推荐

  1. CF Gym 100685A Ariel

    传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. urllib2.URLError: <urlopen error [Errno 10061] >

    今天来运行以前的python脚本,结果报这个错:urllib2.URLError: <urlopen error [Errno 10061] > 原来是因为 解决方法:打开IE浏览器,依次 ...

  3. shared_ptr<> reset

    // std_tr1__memory__shared_ptr_reset.cpp // compile with: /EHsc #include <memory> #include < ...

  4. centOS下yum安装配置samba

     centOS下yum安装配置samba 2010-03-29 15:46:00 标签:samba yum centOS 安装 休闲 注意:本文的原则是只将文件共享应用于内网服务器,并让将要被共享的目 ...

  5. chrome 插件开发

    写在开头: 相当有意思的UI界面,编码实现,浏览速度.对于一天浏览器使用超过10个小时的人来说,能够定制自己的浏览器,是相当的具有诱惑力. Getting Started 1:目前不支持标准发布版本的 ...

  6. hdu 2044 一只小蜜蜂

    斐波那契数列变形,在本题中不是从1-N,而是从M-N 下标   1   2   3   4   5   6   7     8     9 值     1   1   2   3   5   8   ...

  7. 织梦DedeCMS调用二级子栏目或者多级栏目解决方法

    本文是关于织梦DedeCMS调用多级子栏目的,拿来测试分享下.DEDECMS v5.7,后台已建栏目目录,如下图1所示: 图1 DEDECMS后台栏目结构 现在,我们先来调用顶级栏目"站长新 ...

  8. 通用跨站脚本攻击(UXSS)

    有同学问,用百度搜索了下,发现国内相关介绍基本是没有,就写篇文章来介绍下.不过看到有现成的介绍,就拿来翻译修改下.本文的内容主要翻译来自该文章,把一些没必要的话给删了,做了一些整理修改,然后补充一些案 ...

  9. svn代码回滚命令

    代码回滚提交: 比如要把73回滚到68 svn merge -r 73:68 http://my.repository.com/my/project/trunk 然后commit就行了 svn com ...

  10. mysql delete删除记录数据库空间不减少问题解决方法

    记得在中学时学计算机时老师就告诉我delete删除记录只是给数据库中的记录加一个删除标识了,这样数据库空间并不是减少了,当时没想这么多,昨天发现一个数据库利用delete 删除之后容量没变,后来百度了 ...