이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 1e6 + 5;
int N, M;
int cnt[MX];
vector<array<int,3>> v;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> M;
for(int i = 0; i < N; i++) {
int l, r;
cin >> l >> r;
v.push_back({l, r, i});
v.push_back({r, l, i});
}
sort(v.begin(), v.end());
int cur = 0;
while(1) {
array<int,3> arr = {cur + 1, 0, 0};
auto nxt = lower_bound(v.begin(), v.end(), arr);
cout << cur << " -> " << (*nxt)[1] << '\n';
if(nxt == v.end()) break;
cur = (*nxt)[1];
cnt[(*nxt)[2]]++;
}
ll ans = 0, x = 0, y = 0;
for(int i = 0; i < N; i++) {
if(cnt[i] == 2) {
ans += 2;
} else if(cnt[i] == 1) {
x++;
ans += 1;
} else {
y++;
}
}
while(x > 0 && M > 0) {
x--;
ans++;
M--;
ans += 2;
if(y > 0) {
x++;
y--;
ans++;
}
}
if(y > 0 && M > 0) {
ll m = min(y, 1ll * M);
ans += 2 * m;
y -= m;
M -= m;
}
while(M > 0) {
M -= 2;
ans += 4;
}
ans += M & 1;
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |