QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368401#4373. Swap Spacecciafrino#WA 1ms3780kbC++20797b2024-03-27 02:56:402024-03-27 02:56:42

Judging History

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

  • [2024-03-27 02:56:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3780kb
  • [2024-03-27 02:56:40]
  • 提交

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 max(S[i], lhs + S[j]) < max(S[j], rhs + S[i]);
		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';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
6 6
1 7
3 5
3 5

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

4
2 2
3 3
5 1
5 10

output:

5

result:

ok single line: '5'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

1
42 41

output:

42

result:

ok single line: '42'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3576kb

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: 0ms
memory: 3776kb

input:

5
2000 1999
20 1
20 19
3500 1000
5000 4000

output:

7521

result:

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