QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368398 | #4373. Swap Space | cciafrino# | WA | 1ms | 3836kb | C++20 | 761b | 2024-03-27 02:50:53 | 2024-03-27 02:50:53 |
Judging History
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'