题目链接:http://codeforces.com/contest/1015/problem/C

就是输入n和m,m为存储空间

然后n行a和b   a大于b

每一行的a可以压缩为b的大小

求最少只需要压缩几个,使得m可以存下所有数据

如果全部压缩都不满足,就输出-1

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <map>
#include <vector>
#define ll long long
using namespace std;
const int maxn=1e5+10;
ll a[maxn],b[maxn],c[maxn];
bool cmp(ll a,ll b)
{return a>b;
}int main()
{ll n,m;while(scanf("%lld%lld",&n,&m)!=EOF){   ll sum1=0,sum2=0,sum3;for(int i=1;i<=n;i++){scanf("%lld%lld",&a[i],&b[i]);sum1+=a[i];sum2+=b[i];c[i]=a[i]-b[i];}sort(c+1,c+n+1,cmp);// cout<<sum1<<" "<<sum2<<endl;int i=1;int ans=0;if(sum2>m)printf("-1\n");else{ll t=sum1-m;while(t>0){//cout<<c[i]<<" "<<t<<endl;t-=c[i++];ans++;}printf("%d\n",ans);}}return 0;
}

C. Songs Compression

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Ivan has nn songs on his phone. The size of the ii-th song is aiai bytes. Ivan also has a flash drive which can hold at most mm bytes in total. Initially, his flash drive is empty.

Ivan wants to copy all nn songs to the flash drive. He can compress the songs. If he compresses the ii-th song, the size of the ii-th song reduces from aiai to bibi bytes (bi<aibi<ai).

Ivan can compress any subset of the songs (possibly empty) and copy all the songs to his flash drive if the sum of their sizes is at most mm. He can compress any subset of the songs (not necessarily contiguous).

Ivan wants to find the minimum number of songs he needs to compress in such a way that all his songs fit on the drive (i.e. the sum of their sizes is less than or equal to mm).

If it is impossible to copy all the songs (even if Ivan compresses all the songs), print "-1". Otherwise print the minimum number of songs Ivan needs to compress.

Input

The first line of the input contains two integers nn and mm (1≤n≤105,1≤m≤1091≤n≤105,1≤m≤109) — the number of the songs on Ivan's phone and the capacity of Ivan's flash drive.

The next nn lines contain two integers each: the ii-th line contains two integers aiai and bibi (1≤ai,bi≤1091≤ai,bi≤109, ai>biai>bi) — the initial size of the ii-th song and the size of the ii-th song after compression.

Output

If it is impossible to compress a subset of the songs in such a way that all songs fit on the flash drive, print "-1". Otherwise print the minimum number of the songs to compress.

Examples

input

Copy

4 21
10 8
7 4
3 1
5 4

output

Copy

2

input

Copy

4 16
10 8
7 4
3 1
5 4

output

Copy

-1

Note

In the first example Ivan can compress the first and the third songs so after these moves the sum of sizes will be equal to 8+7+1+5=21≤218+7+1+5=21≤21. Also Ivan can compress the first and the second songs, then the sum of sizes will be equal 8+4+3+5=20≤218+4+3+5=20≤21. Note that compressing any single song is not sufficient to copy all the songs on the flash drive (for example, after compressing the second song the sum of sizes will be equal to 10+4+3+5=22>2110+4+3+5=22>21).

In the second example even if Ivan compresses all the songs the sum of sizes will be equal 8+4+1+4=17>168+4+1+4=17>16.

cf-#501 div3 C. Songs Compression相关推荐

  1. CF1015C Songs Compression (#贪心)

    题目描述 Ivan has nn songs on his phone. The size of the ii -th song is a_iai​ bytes. Ivan also has a fl ...

  2. 【贪心】Songs Compression

    17暑假练习赛2 Codeforces Round #501 (Div. 3)  1015C 贪心水题,思路简单 坑点:不开long long会过不去,以后统一用long long做题 失误:考虑到了 ...

  3. codeforces cf 521(div3) E题

    本题让我重视到对lower_bound这个函数不是特别会用. lower_bound(int * ,int *,int ) 第一个参数是数组首地址,由于c++语言的特殊性,传入第一个参数可以是数组首地 ...

  4. Songs Compression

    https://codeforces.com/contest/1015/problem/C C++版本一 简单排序 /* *@Author: STZG *@Language: C++ */ #incl ...

  5. CodeForces 1015 C Songs Compression

    [题目]http://codeforces.com/contest/1015/problem/C [大意]硬盘容量为21,有4首歌,前是原来大小,后是压缩大小,问最少压缩多少个能全装下. [代码] # ...

  6. 【CF #797 Div3】A-E

    A. Print a Pedestal (Codeforces logo?) 题目 分析 一个数n,h1,h2,h3满足h1+h2+h3=n;h1>h2>h3.找出最小的h1. 判断n是否 ...

  7. 【CF #811 Div3】 A-E

    A. Everyone Loves to Sleep 题目 分析 24小时值,算出n个时间点与HM时间点的最短时间段. 将小时转换为分钟,算时间差,最后再转换为小时分钟. 代码 #include< ...

  8. CF 863 div3 A-C

    第一题题意在一个长度为n的数字中插入一个数m使得插入之后的数最大 首先我们可以大概思考一下如果m很大那么应该插入到越前面越好 相等的时候却不是比如 23   2   如果直接插入会变成  223 但是 ...

  9. Codeforces Round #501 (Div. 3)【未完结】

    2022.3.7 题单地址:https://codeforces.com/contest/1015 目录 A. Points in Segments B. Obtaining the String[模 ...

最新文章

  1. 腾讯以及各大厂的 C++ 开发环境是什么样的?
  2. 自定义HTTP标头:命名约定
  3. 会声会影x7 每次安装均会提示:已安装这个产品的另一个版本
  4. 如何使用 Docker 部署一个基于 Play Framework 的 Scala Web 应用?
  5. Sublime Text3 安装SublimeLinter
  6. C/C++:Windows编程—Hook IE浏览器实现URL拦截及更改(下)
  7. 烂泥:ubuntu中使用virt-manager图形化新建虚拟机
  8. bzoj1225 [HNOI2001] 求正整数 约数个数定理+对数
  9. The Clean Architecture--一篇很不错的关于架构的文章
  10. BZOJ3711 : [PA2014]Druzyny
  11. Linux下编译安装redis,详细教程
  12. docker代理配置详解
  13. VMP3.6的反调试和反虚拟机
  14. Qt: 解决Qt语言家 更新翻译(lupdate) 非常慢卡死没反应现象
  15. 让国内顶尖程序员社区“牛客网”低头的这份Java面试手册真的强
  16. 应用程序正常初始化(0xc0150002)失败。请单击“确定”,终止应用程序
  17. 应用数据安全,任重而道远
  18. 263企业邮箱服务器是什么,千万别用263企业邮箱 - 外贸邮箱邮件群发 - 电脑网络 - 福步外贸论坛(FOB Business Forum) |中国第一外贸论坛...
  19. sdcc对应stc51单片机
  20. 致远OA任意文件上传

热门文章

  1. python pitfall (陷阱)--不同平台os模块文件名排序
  2. 金色传说:SAP-FICO-参考加权因素维护执行成本中心分配 KSV5/KSV3报错GA603:系统错误:集01018000D06表CCSS读出错
  3. 保存numpy数组到excel
  4. Github最新客户端的简单使用教程
  5. image失败 安装scikit_安装SciKitImage错误127
  6. Android 使用三种方式缓存加载 倒影图片
  7. csgo服务器搭建(linux)
  8. Apollo星火计划学习笔记——第八讲Apollo控制模块解析与实践1
  9. 运行最新创建的镜像:
  10. OpenTracing语义标准