使用C++輸入輸出TLE,輸出使用 %lld 會WA,要用%i64d輸出
題目沒有什麼陷阱
[html]
// File Name: hdu4221.cpp
// Author: bo_jwolf
// Created Time: Wednesday, May 08, 2013 PM01:15:20 HKT
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<queue>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
typedef long long ll ;
const int maxn = 100005 ;
struct node
{
int a , b ;
}edge[ maxn ] ;
bool cmp( node x , node y )
{
return x.b < y.b ;
}
int main()
{
int t , n ;
int k = 0 ;
scanf( "%d" , &t ) ;
while( t-- )
{
k++ ;
scanf( "%d" , &n ) ;
for( int i = 0 ; i < n ; i++ )
scanf( "%d%d" , &edge[ i ].a , &edge[ i ].b ) ;
long long sum = 0 ;
long long ans = 0 ;
sort( edge , edge + n , cmp ) ;
for( int i = 0 ; i < n ; i++ )
{
sum += edge[ i ].a ;
if( sum - edge[ i ].b > ans )
ans = sum - edge[ i ].b ;
}
printf( "Case %d: %I64d\n" , k , ans ) ;
}
return 0;
}
// File Name: hdu4221.cpp
// Author: bo_jwolf
// Created Time: Wednesday, May 08, 2013 PM01:15:20 HKT
#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<queue>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
typedef long long ll ;
const int maxn = 100005 ;
struct node
{
int a , b ;
}edge[ maxn ] ;
bool cmp( node x , node y )
{
return x.b < y.b ;
}
int main()
{
int t , n ;
int k = 0 ;
scanf( "%d" , &t ) ;
while( t-- )
{
k++ ;
scanf( "%d" , &n ) ;
for( int i = 0 ; i < n ; i++ )
scanf( "%d%d" , &edge[ i ].a , &edge[ i ].b ) ;
long long sum = 0 ;
long long ans = 0 ;
sort( edge , edge + n , cmp ) ;
for( int i = 0 ; i < n ; i++ )
{
sum += edge[ i ].a ;
if( sum - edge[ i ].b > ans )
ans = sum - edge[ i ].b ;
}
printf( "Case %d: %I64d\n" , k , ans ) ;
}
return 0;
}