QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#368398#4373. Swap Spacecciafrino#WA 1ms3836kbC++20761b2024-03-27 02:50:532024-03-27 02:50:53

Judging History

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

  • [2024-03-27 02:50:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3836kb
  • [2024-03-27 02:50:53]
  • 提交

answer

#include<bits/stdc++.h>

int main() {
	using namespace std;
	cin.tie(nullptr)->sync_with_stdio(false);
	int N; cin >> N;

	using i64 = int64_t;

	vector<i64> S(N), E(N);
	for (int i = 0; i < N; ++i) cin >> S[i] >> E[i];

	vector<int> id(N); iota(id.begin(), id.end(), 0);

	sort(id.begin(), id.end(), [&](const auto& i, const auto& j) {
		i64 lhs = E[i] - S[i];
		i64 rhs = E[j] - S[j];
		if (lhs >= 0 && rhs < 0) return true;
		if (lhs < 0 && rhs >= 0) return false;
		if (lhs < 0 && rhs < 0) return E[i] < E[j];
		return S[i] < S[j];
	});

	i64 cur = 0, ans = 0;
	for (int i = 0; i < N; ++i) {
		if (S[id[i]] > cur) {
			ans += S[id[i]] - cur;
			cur = S[id[i]];
		}
		cur += E[id[i]] - S[id[i]];
	}

	cout << ans << '\n';
}

详细

Test #1:

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

input:

4
6 6
1 7
3 5
3 5

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3836kb

input:

4
2 2
3 3
5 1
5 10

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3580kb

input:

1
42 41

output:

42

result:

ok single line: '42'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

5
3000 500000
20 21
20 100
4000 4001
4000 4100

output:

2919

result:

ok single line: '2919'

Test #5:

score: -100
Wrong Answer
time: 1ms
memory: 3632kb

input:

5
2000 1999
20 1
20 19
3500 1000
5000 4000

output:

7521

result:

wrong answer 1st lines differ - expected: '5000', found: '7521'