problem 1008 Chengdu

problem 1008 Chengdu
1008
# include  < cstdio >
# include 
< algorithm >

# define N 
100005

typedef __int64 LL;

int  n;
int  a[N], b[N], r[N];
bool  cmp( int  x,  int  y)
{
                
return  a[x] - b[y]  ==  a[y] - b[x]  ?  a[x] > a[y] : a[x] - b[y] > a[y] - b[x];
}
int  main()
{
                freopen(
" in.txt " " r " , stdin);

                
int  i;
                LL w, ans;
                
while  ( ~ scanf( " %d " & n))
                {
                                
for  (i  =   0 ; i  <  n;  ++ i)
                                                scanf(
" %d%d " & a[i],  & b[i]), r[i]  =  i;
                                std::sort(r, r
+ n, cmp);
                                w 
=  a[ r[n - 1 ] ];
                                ans 
=   0 ;
                                
for  (i  =  n - 2 ; i  >=   0 -- i)
                                {
                                                
if  (ans  <  w - (LL)b[ r[i] ]) ans  =  w  -  (LL)b[ r[i] ];
                                                w 
+=  (LL)a[ r[i] ];
                                }
                                printf(
" %I64d\n " , ans);
                }

                
return   0 ;
}

你可能感兴趣的:(problem 1008 Chengdu)