【CF1015C】Songs Compression(贪心)
题意:
给定n和m,n组(a[i],b[i]),每一组a[i]可以压缩为b[i],求最少只需要压缩几个,使得m可以存下所有数据,无解输出-1
思路:按差贪心,排序
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair const int N=; PII a[N];
int n,m; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} bool cmp(const PII &a,const PII &b)
{
return a.fi-a.se>b.fi-b.se;
} int main()
{
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
scanf("%d%d",&n,&m);
ll s=;
for(int i=;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
a[i]=MP(x,y);
s+=x;
}
sort(a+,a+n+,cmp);
int ans=;
for(int i=;i<=n;i++)
{
if(s>m) {s-=a[i].fi-a[i].se; ans++;}
else break;
}
if(s>m) printf("-1");
else printf("%d",ans);
return ;
}
【CF1015C】Songs Compression(贪心)的更多相关文章
- C. Songs Compression(简单贪心)
水题 #include<iostream> #include<algorithm> using namespace std; #define LL long long ; st ...
- codeforces 651E E. Table Compression(贪心+并查集)
题目链接: E. Table Compression time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- UVA - 1346 Songs (贪心+排序)
题意:已知每首歌的标号,长度和播放频率,求一种播放顺序,使得最小,并且输出该播放顺序下第t首歌的标号. 分析: 1.长度越短,播放频率越大的歌排在前面,上式越小. 2.s(i)表示的是当前播放顺序下这 ...
- Codeforces Div3 #501 A-E(2) F以后补
感觉自己有点强迫症 不都写出来就找理由不写题解 http://codeforces.com/contest/1015 题目链接 A. Points in Segments 题目意思 n个线段 ...
- codeforces 1015C
C. Songs Compression time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #501 (Div. 3)
A - Points in Segments 题意:implement #include<bits/stdc++.h> using namespace std; typedef long ...
- 1346 - Songs (贪心)
John Doe is a famous DJ and, therefore, has the problem of optimizing the placement of songs on his ...
- [CF1523C] Compression and Expansion (DP/贪心)
C. Compression and Expansion 题面 一个合法的表单由横向 N N N 行数字链,纵向一层或多层数字链组成,第 k k k 层的数字链(可以想象为前面打了 k k k 个制表 ...
- uva 1346 - Songs(贪心)
题目链接:uva 1346 - Songs 题目大意:John Doe 是一个著名的DJ,现在他有n首播放个曲, 每首歌曲有识别符key,歌曲长度l,以及播放频率q.想在John Doe 想将磁带上的 ...
随机推荐
- shell脚本,awk利用NF来计算文本显示的行数。
解释: 1.awk 'NF{a++;print a,$0;next}1' file4 首先判断NF是否存在值,第一行第二行第三行第四行都存在,进行执行后面的输出,输出后碰到next后,就结束了后面的操 ...
- 02_5if switch分支与循环语句
02_5if switch分支与循环语句 1.语句 1.1条件语句-根据不同条件,执行不同语句. if if ... else if ... else if if ... else if ... el ...
- Apache超时配置
Apache超时配置 1. KeepAliveTimeout 语法 KeepAliveTimeout seconds 默认 5 上下文 server config, virtual host 说明 服 ...
- c++调用系统关机命令 c++调用暂停命令
#include<stdlib.h> int main() { //调用系统dos命令 system("shutdown -s -t 120"); ; } system ...
- attachEvent和addEventListener 的使用方法和区别
attachEvent方法,为某一事件附加其它的处理事件.(不支持Mozilla系列)addEventListener方法 用于 Mozilla系列document.getElementById(&q ...
- 安装mysqlclient失败
环境:python3.6 sudo apt-get install python3.6-dev sudo apt-get install default-libmysqlclient-dev 参考:h ...
- 21.Yii2.0框架多表关联一对多查询之性能优化--模型的使用
控制器里 功能: 通过分类,查分类下的所有文章 //关联查询 public function actionRelatesearch(){ //关联查询 //查询方法一(查一行) 一维数组下的值是obj ...
- UVa - 12096 集合栈计算机(STL)
[题意] 有一个专门为了集合运算而设计的“集合栈”计算机.该机器有一个初始为空的栈,并且支持以下操作:PUSH:空集“{}”入栈DUP:把当前栈顶元素复制一份后再入栈UNION:出栈两个集合,然后把两 ...
- POJ:3160-Father Christmas flymouse
Father Christmas flymouse Time Limit: 1000MS Memory Limit: 131072K Description After retirement as c ...
- 《小团团团队》第八次团队作业:Alpha冲刺
项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 小团团团队 作业学习目标 (1)掌握软件测试基础技术; (2)学 ...