QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#695601#6693. Fast and Fatxfs001TL 1462ms7704kbC++14797b2024-10-31 20:25:222024-10-31 20:25:23

Judging History

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

  • [2024-10-31 20:25:23]
  • 评测
  • 测评结果:TL
  • 用时:1462ms
  • 内存:7704kb
  • [2024-10-31 20:25:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,a[2020000],w[2020000];
bool ch(int x){
	multiset<int>s;
	for(int i=1;i<=n;i++){
		if(a[i]<x){
			s.insert(w[i]);}
	}
	// sort(s.begin(),s.end());
	for(int i=1;i<=n;i++){	
		if(a[i]<x)continue;
		int t=a[i]-x+w[i];
		auto it=upper_bound(s.begin(),s.end(),t);
		if(it!=s.begin()){
			it--;
			s.erase(it);
		}
		if((int)s.size()<=0)break;
	}
	if((int)s.size()>0)return false;
	return true;
}
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i]>>w[i];
	int l=0,r=1e9;
	while(l<r){
		int mid=l+r+1>>1;
		if(ch(mid))
			l=mid;
		else
			r=mid-1;
	}
	cout<<l<<'\n';
}
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int t=1;
	cin>>t;
	while(t--)
		solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5596kb

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: 0
Accepted
time: 122ms
memory: 5540kb

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
610497257
576427565
636500913
315900406
370430730
526259135
781258283
631916852
300930080
419999540
431930706
479323438
530080165
391912906
708925499
467782812
457987604
389750718
447390353
696516804
...

result:

ok 10000 numbers

Test #3:

score: 0
Accepted
time: 1462ms
memory: 7704kb

input:

400
908
33362229 606508747
632419478 324326751
257284260 336303174
457246243 986284341
542591728 520499949
519145521 971093641
633038285 374866966
137832222 929747560
626840805 488847915
750542462 328721976
928847956 932651817
479954326 140789806
794986794 212084514
372002273 933710809
173161453 119...

output:

504394967
484359492
469225546
475096879
595868798
497700736
456321846
407898878
591377003
568847769
747288891
512226022
532505353
472511102
511795703
477459477
529231318
472548529
525635770
487622149
510138466
527879972
504505269
498990235
475265402
514165957
449627768
450001628
349076692
507182026
...

result:

ok 400 numbers

Test #4:

score: -100
Time Limit Exceeded

input:

10
20711
764663709 192212865
55777289 890465487
406536728 278177638
204765968 477730025
379283253 654167175
41026104 774138002
875860206 465532238
934199361 38168843
545038187 933648246
99831648 715642411
984100235 592340109
870539197 676140250
2503522 500646009
813801461 79167382
531368117 16295473...

output:


result: