QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#400561#6693. Fast and Fatliutaowoaini#WA 66ms5676kbC++171.4kb2024-04-27 13:44:512024-04-27 13:44:52

Judging History

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

  • [2024-04-27 13:44:52]
  • 评测
  • 测评结果:WA
  • 用时:66ms
  • 内存:5676kb
  • [2024-04-27 13:44:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int n;
struct node
{
	int v;
	int w;
}xiaoyu[N];
struct nodes
{
	int v;
	int w;
}xjh[N];
bool cmp1(node x, node y)
{
	return x.v + x.w > y.v + y.w;
}
bool cmp2(nodes x, nodes y)
{
	return x.w > y.w;
}
bool check(int x)
{
	vector<int>a;
	vector<int>b;
	//找速度比较大的
	for (int i = 1; i <= n; i++)
	{
		if (xiaoyu[i].v > x) a.push_back(xiaoyu[i].v + xiaoyu[i].w - x);//根据v+w排序,所以体重也是排序
	}
	//找速度比较小的
	for (int i = 1; i <= n; i++)
	{
		if (xjh[i].v < x) b.push_back(xjh[i].w);
	}
	//左面数量少    速度太大
	if (a.size() < b.size()) return false;
	else
	{
		int len = b.size();
		for (int i = 0; i < len; i++)
		{
			if (a[i] < b[i]) return false;//不够背
		}
	}
	return true;
}
void solve()
{
	cin >> n;
	int l = 1e9 + 10;
	int r = -1;
	for (int i = 1; i <= n; i++)
	{
		int v, w;
		cin >> v >> w;
		l = min(l, v);
		r = max(r, v);
		xiaoyu[i].v = v;
		xiaoyu[i].w = w;
		xjh[i].v = v;
		xjh[i].w = w;
	}
	sort(xiaoyu + 1, xiaoyu + 1 + n, cmp1);
	sort(xjh + 1, xjh + 1 + n, cmp2);
	while (l < r)
	{
		int mid = (l + r+1) >> 1;
		if (check(mid))l = mid;
		else r = mid -1;
	}
	cout << l << endl;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

详细

Test #1:

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

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: 66ms
memory: 3564kb

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'