bzoj1148
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1148
c[n]+w[n]<c[n+1]+w[n+1]
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex>
//#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj using namespace std; typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define re(i,a,b) for(i=a;i<=b;i++)
#define red(i,a,b) for(i=a;i>=b;i--)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define SF scanf
#define PF printf
#define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-;
inline int sgn(DB x){if(abs(x)<EPS)return ;return(x>)?:-;}
const DB Pi=acos(-1.0); inline int gint()
{
int res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
}
inline LL gll()
{
LL res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
} const int maxN=; int N;
struct Tdata{LL C,W;}data[maxN+]; inline bool cmp(Tdata a,Tdata b){return a.C+a.W<b.C+b.W;} struct cmp2{inline bool operator()(Tdata a,Tdata b){return a.W<b.W;}};
priority_queue<Tdata,vector<Tdata>,cmp2> Q;
LL ans; int main()
{
freopen("bzoj1148.in","r",stdin);
freopen("bzoj1148.out","w",stdout);
int i;
N=gint();
re(i,,N)data[i].C=LL(gint()),data[i].W=LL(gint());
sort(data+,data+N+,cmp);
re(i,,N)
if(ans<=data[i].C)
{
ans+=data[i].W;
Q.push(data[i]);
}
else
if(data[i].W<Q.top().W && ans-Q.top().W<=data[i].C)
{
ans-=Q.top().W;
Q.pop();
ans+=data[i].W;
Q.push(data[i]);
}
cout<<Q.size()<<endl;
cout<<ans<<endl;
return ;
}
bzoj1148的更多相关文章
随机推荐
- OI生涯中三届NOIP(2012-2014)流水账
NOIP2012: 才摸了三四个月OI就上阵当炮灰,果然一下就被轰得渣都不剩了. D1看到T1这道模拟水题时很激动,立马就把它A了.然后T2就不会了,果断写了个阶乘的暴力,根本没有想过什么排序贪心.T ...
- 型牌男装施春蕾:分拆让马云对淘宝定位更清晰--互联网 -- CCTIME飞象网
型牌男装施春蕾:分拆让马云对淘宝定位更清晰--互联网 -- CCTIME飞象网 型牌男装施春蕾:分拆让马云对淘宝定位更清晰 2011年6月17日 13:16 CCTIME飞象网 ...
- Python进阶(面向对象编程基础)(四)
1.方法也是属性 我们在 class 中定义的实例方法其实也是属性,它实际上是一个函数对象: class Person(object): def __init__(self, name, score) ...
- IOS如何延长LaunchScreen.xib启动画面
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...
- Django之路由系统
一.路由系统介绍 在django程序中,可以通过urls.py文件对所有的url进行任务的分配,根据路由规则的定义选择不同的业务处理函数进行处理 二.路由规则定义 1.路由规则代码如下,mysite/ ...
- Javascript:splice()方法实现对数组元素的插入、删除、替换及去重
定义和用法 splice() 方法向/从数组中添加/删除项目,然后返回被删除的项目. 注释:该方法会改变原始数组. 语法: Array.prototype.splice(index,count[,el ...
- Javascript:charCodeAt()方法及示例
js charCodeAt()函数说明 返回一个整数,代表指定位置上字符的 Unicode 编码.该Unicode编码为十六进制 strObj.charCodeAt(index) 参数: strObj ...
- #python-dateutil下载地址
http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil
- [ES6] When should use Map instead of Object
Use Maps when keys are unknown until runtime: Map: let recentPosts = new Map(); createPost( newPost, ...
- canvas--画宇宙
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" ...