# 描述

http://www.lydsy.com/JudgeOnline/problem.php?id=1620

# 分析

 1 #include <bits/stdc++.h>
2 #define fst first
3 #define scd second
4 using namespace std;
5
6 typedef pair <int,int> P;
7 const int maxn=1000+5;
8 int n,Max=~0u>>1;
9 P a[maxn];
10 inline int read(int &x){x=0;int k=1;char c;for(c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')k=-1;for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';return x*=k;}
11 inline bool cmp(P a,P b){ return a.scd<b.scd; }
12 inline bool C(int x){
13     for(int i=1,t=x-1;i<=n;i++){
14         t+=a[i].fst;
15         if(t>=a[i].scd) return false;
16     }
17     return true;
18 }
19 inline int bsearch(int l,int r){
20     while(l<r){
21         int mid=l+(r-l+1)/2;
22         if(C(mid)) l=mid;
23         else r=mid-1;
24     }
25     return l;
26 }
27 inline void init(){
30     sort(a+1,a+n+1,cmp);
31 }
32 int main(){
33     init();
34     int ans=bsearch(0,Max);
35     if(ans==0) ans=-1;
36     printf("%d\n",ans);
37     return 0;
38 }
View Code

posted @ 2016-06-23 20:59  晴歌。  阅读(159)  评论(0编辑  收藏  举报