QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#426005#6693. Fast and FatONISINOWA 11ms3612kbC++201.6kb2024-05-30 20:13:462024-05-30 20:13:48

Judging History

你现在查看的是最新测评结果

  • [2024-05-30 20:13:48]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3612kb
  • [2024-05-30 20:13:46]
  • 提交

answer

#include <bits/stdc++.h>

//DEBUG:    https://github.com/sharkdp/dbg-macro
#ifdef LOCAL
#include "../dbg-macro-0.5.1/dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif

#define endl '\n'
using namespace std;
typedef long long ll;
const ll MAXN=2e5+10,MOD=1e9+7,INF=1e9;

ll qpow(ll base,ll exp){ll ans=1;while(exp){if(exp&1)(ans*=base)%=MOD;(base*=base)%=MOD;exp>>=1;}return ans;}
template<class T>ll max_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r+1)/2;if(cmp^!check(m))l=m;else r=m-1;}return l;}
template<class T>ll min_binary_answer(ll l,ll r,T check,bool cmp=true){ll m;while(l<r){m=(l+r)/2;if(cmp^!check(m))r=m;else l=m+1;}return r;}
ll exgcd(ll a,ll b,ll &x,ll &y){ll tmp;return b==0?(x=1,y=0,a):(tmp=exgcd(b,a%b,y,x),y-=(a/b)*x,tmp);}
ll highbit(ll x){for(ll i=1;i<(ll)sizeof(ll)*4;i<<=1)x|=x>>i;return x-(x>>1);}
ll lowbit(ll x){return x&(-x);}
//--------Global declared area--------

//--------Global declared end --------
void solve(int test_num){
	int n;
	cin>>n;
	vector<pair<ll,ll>> a(n+1);
	for(int i=1;i<=n;i++){
		int v,w;
		cin>>v>>w;
		a[i]={v,w};
	}
	sort(a.begin()+1,a.end(),[&](pair<ll,ll>x,pair<ll,ll>y){
		return x.first+x.second<y.second+y.first;
	});
	ll ans=1e9;
	if(n==1){
		cout<<a[n].first;
		return;
	}else{
		if(a[n].second>=a[n-1].second){
			ans=min(ans,a[n].first);
		}else ans=min(ans,a[n].first-(a[n-1].second-a[n].second));
	}
	cout<<ans<<'\n';
	return;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr),std::cout.tie(nullptr);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++){
		solve(i);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

2
5
10 5
1 102
10 100
7 4
9 50
2
1 100
10 1

output:

8
1

result:

ok 2 number(s): "8 1"

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 3592kb

input:

10000
4
280251502 664541723
375808746 641141991
95134537 898607509
455259328 944978891
2
798417052 547329847
785434740 991778535
6
623628702 857611223
275667427 453747403
292209526 283132767
330752033 988721243
470297536 608192332
477186035 325224271
3
280572174 994054447
306566740 923535026
3781360...

output:

455259328
785434740
492518682
280572174
859034865
960871619
852497327
947133410
136979645751423030
818851530
679186856
830835709
315900406
683472128
775182625
781258283
631916852
355137761
941986610
812952251
747868968
657739840
602104420
722048022
863537431
745319288
579492507
798382479
696516804
7...

result:

wrong answer 1st numbers differ - expected: '352409014', found: '455259328'