QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618541#6693. Fast and FatxiaofangerWA 60ms3860kbC++171.3kb2024-10-06 23:27:072024-10-06 23:27:07

Judging History

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

  • [2024-10-06 23:27:07]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:3860kb
  • [2024-10-06 23:27:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

void solve() {
	
	int n; cin >> n;
	
	vector<pair<int , int>> a(n);
	for(int i = 0 ; i < n ; i++) cin >> a[i].first >> a[i].second;
	
	sort(a.begin() , a.end() ,
	[&](pair<int , int> A , pair<int , int> B){
		return A.first + A.second > B.first + B.second;	
	});
	
	auto b = a;
	sort(b.begin() , b.end() ,
	[&](pair<int , int> A , pair<int , int> B){
		return A.second > B.second;
	});
	
	auto check = [&](int x){
		vector<int> d , s;
		for(int i = 0 ; i < n ; i++){
			if(a[i].first > x){
				d.push_back(a[i].first + a[i].second - x);
			}
			if(b[i].first < x){
				s.push_back(b[i].second);
			}
		}
		
		//cout << d.size() << ' ' << s.size() << '\n';
		if(d.size() < s.size()) return false;
		for(int i = 0 ; i < s.size() ; i++) if(d[i] < s[i]) return false;
		return true;
	};
	
	int le = 1 , ri = 1e9 , ans = 1;
	while(le <= ri){
		int mid = (le + ri) >> 1;
		//cout << le << ' ' << mid << ' ' << ri << '\n';
		if(check(mid)){
			le = mid + 1;
			ans = mid;
		}
		else ri = mid - 1;
	}
	
	//cout << '\n';
	cout << ans << '\n';
	//cout << '\n';
	
}

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
   	
    int __ = 1;
    cin >> __;
    
	while(__--){
   		solve();
   	}
    return 0;
}








 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 60ms
memory: 3860kb

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:

352409014
785434740
470297535
280572173
704877362
960871618
691253608
560579094
136979645
399988835
610497257
576427564
636500913
315900405
370430730
526259135
781258283
631916851
300930080
419999539
431930706
479323438
530080164
391912906
708925498
467782812
457987604
389750718
447390353
696516804
...

result:

wrong answer 3rd numbers differ - expected: '470297536', found: '470297535'