QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#178042#6693. Fast and Fatvalue0#WA 63ms3936kbC++201.3kb2023-09-13 17:37:332023-09-13 17:37:34

Judging History

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

  • [2023-09-13 17:37:34]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:3936kb
  • [2023-09-13 17:37:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> pii;
#define fi first
#define se second
int n,m,k;
void solve()
{
	scanf("%d",&n);
	vector<pair<ll,int>> v(n + 1),w(n + 1),a(n + 1);
	for(int i = 1;i<=n;i++)
	{
		scanf("%lld %lld",&v[i].fi,&w[i].fi);
		v[i].se = w[i].se = i;
		a[i] = {v[i].fi + w[i].fi,i};
	}
	sort(v.begin(),v.end());
	sort(a.begin(),a.end());
	int l = 0;
	int r = 1e9 + 1;
	auto check = [&](int x)
	{
		vector<int> t,ans;
		vector<bool> st(n + 1);
		for(int i = 1;i<=n;i++)
		{
			if(v[i].fi < x)
			{
				st[v[i].se] = true;
				t.push_back(w[v[i].se].fi);
			}
		}
		for(int i = n;i>=1;i--)
		{
			if(!st[a[i].se])
			{
				ans.push_back(a[i].fi - x);
			}
		}
		reverse(ans.begin(),ans.end());
		if(ans.size() < t.size())
		{
			return false;
		}
		int idx = ans.size()-1;
		for(int i = t.size()-1;i>=0 && idx >= 0;i--)
		{
			while(idx >= 0 && ans[idx] < t[i])
			{
				idx --;
			}
			if(idx >= 0)
			{
				t[i] = 0;
			}
		}
		if(t.empty() || t[0] == 0)
		{
			return true;
		}
		return false;
	};
	while(l + 1 < r)
	{
		int mid = l + r >> 1;
		if(check(mid))
		{
			l = mid;
		}
		else
		{
			r = mid;
		}
	}
	printf("%d\n",l);
	
	
}

int main()
{
	int t = 1;
	scanf("%d",&t);
	while(t--)
	{
		solve();
	}
	return 0;
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 63ms
memory: 3936kb

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:

375808746
785434740
470297536
280572174
704877362
960871619
691253609
560579095
136979645
399988835
715111359
576427565
636500913
315900406
550838706
526259135
781258283
631916852
300930080
419999540
667381564
479323438
530080165
493047741
708925499
509158939
457987604
389750718
447390353
696516804
...

result:

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