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. php版本的discuzX3.2部署的问题收集

    1.登陆后台老是自动退出是怎么回事? 解决方法:用ftp上線下載文件下在跟目錄/config/config_global.php把$_config['admincp']['checkip']  = 1 ...

  2. linux学习笔记二-----文件权限管理

    一.分析文件权限(ln -s 文件名 快捷方式名 用来创建文件的快捷方式,下方ll查看信息时会在第一个字符处显示l) [hjp@bogon ~]$ ll total 4 drwxrwxr-x. 2 h ...

  3. mysql随机获取一条或者多条数据

    原文地址:http://www.im286.com/thread-7091552-1-1.html 转来备份 研究一些随机的因素,主要是讲究效率问题. 语句一: MYSQL手册里面针对RAND()的提 ...

  4. N个数全排列的非递归算法

    //N个数全排列的非递归算法 #include"stdio.h" void swap(int &a, int &b) { int temp; temp = a; a ...

  5. Windows 2008远程多用户登录的配置方法(转载)

    在使用Windows2008远程登录功能时,如果需要进行多用户登录,可以采用以下配置方法: 首先要启用远程桌面这一功能:右击“我的电脑”→属性→远程配置→远程桌面,就可以配置相应的远程桌面功能了.下 ...

  6. linux 中\r

    工作中遇到的一个处理\r和\n的问题,看了一下\r是啥... void File_translater::EspEntr(string& strSrc){ int iPos; while((i ...

  7. word表格断行的问题

    word一个表格如果某一行的 内容 太多,就会自动跑到下一页去了 解决方法是: 在表格上点右键-> 属性 -> "行" -> 去掉"设置行高" ...

  8. c语言的头文件-不是c++类的头文件?

    下面的概述是参考的这篇文章:http://blog.csdn.net/bingxx11/article/details/7771437 c语言编程中也有,也需要头文件, 头文件不只是C++的类才需要! ...

  9. linux 查找php.ini 文件

    sudo find /* -name 'php.ini' /etc/php5/fpm/php.ini

  10. sh脚本学习之: sh脚本 、sed、awk

    sh脚本 sh命令的批处理文件,支持更复杂的逻辑. Shell中的变量 参数 $0 当前脚本路径 $1....$n 脚本执行对应的第n个参数 条件判断 文件判断 test [op] path e存在 ...