QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#178082#6693. Fast and Fatvalue0#WA 0ms4088kbC++201.4kb2023-09-13 17:51:202023-09-13 17:51:21

Judging History

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

  • [2023-09-13 17:51:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4088kb
  • [2023-09-13 17:51:20]
  • 提交

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)
			{
				idx --;
				t[i] = 0;
			}
		}
		if(t.empty() || t[0] == 0)
		{
			return true;
		}
		return false;
	};
	while(l + 1 < r)
	{
		int mid = l + r >> 1;
//		cout<<mid<<endl;
		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: 0
Wrong Answer
time: 0ms
memory: 4088kb

input:

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

output:

7
1

result:

wrong answer 1st numbers differ - expected: '8', found: '7'