QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#183761#6693. Fast and Fatliuzhenhao09#WA 125ms7904kbC++141.5kb2023-09-19 20:08:502023-09-19 20:08:51

Judging History

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

  • [2023-09-19 20:08:51]
  • 评测
  • 测评结果:WA
  • 用时:125ms
  • 内存:7904kb
  • [2023-09-19 20:08:50]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
struct node{
	int v,w;
	bool operator <(const node& kkk)const{
		return v < kkk.v;
	}
}a[100010],b[100010],c[100010];
int T,n,tot1 = 0,tot2 = 0;
bool cmp1(node A,node B){
	return A.w > B.w;
}
bool cmp2(node A,node B){
	return A.w + A.v < B.w + B.v;
}
bool check(int x){
	tot1 = tot2 = 0;
	for(int i = 1; i <= n; i++){
		if(a[i].v < x) b[++tot1] = a[i];
		else c[++tot2] = a[i];
	}
	sort(b + 1,b + tot1 + 1,cmp1);
	sort(c + 1,c + tot2 + 1,cmp2);
	multiset<pii>s;
	multiset<int>t;
	multiset<pii>::iterator it;
	multiset<int>::iterator ti;
	for(int i = 1; i <= tot2; i++) s.insert(make_pair(c[i].w,c[i].v + c[i].w)),t.insert(c[i].v + c[i].w);
	if(tot1 > tot2) return 0;
	for(int i = 1; i <= tot1; i++){
		if(s.empty()) return 0;
		it = s.lower_bound(make_pair(b[i].w,0));
		if(it != s.end()){
			if(t.find((*it).second) != t.end()) t.erase(t.find((*it).second));
			s.erase(it);
		} 
		else{
			if(t.empty()) return 0;
			ti = t.end();
			ti--;
			if((*ti) - b[i].w < x) return 0;
			t.erase(ti);
		}
	}
	return 1;
}
signed main(){
	scanf("%lld",&T);
	while(T--){
		scanf("%lld",&n);
		int mx = 0;
		for(int i = 1; i <= n; i++) scanf("%lld %lld",&a[i].v,&a[i].w),mx = max(mx,a[i].v);
		sort(a + 1,a + n + 1);
		int l = 1,r = mx;
		while(l < r){
			int mid = (l + r + 1) >> 1;
			if(check(mid)) l = mid;
			else r = mid - 1;
		}
		printf("%lld\n",l);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 125ms
memory: 7904kb

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
470297536
280572174
704877362
960871619
691253609
560579095
136979645
399988835
617782160
576427565
636500913
315900406
370430730
526259135
781258283
631916852
300930080
419999540
667381564
479323438
530080165
391912906
708925499
509158939
457987604
389750718
447390353
696516804
...

result:

wrong answer 11th numbers differ - expected: '610497257', found: '617782160'