이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
int main() {
int n;
cin >> n;
vector<pi> candies(n);
for (int i = 0; i < n; i++) {
int s, t;
cin >> s >> t;
candies[i] = make_pair(s - t, s + t);
}
sort(candies.begin(), candies.end(), [](const pi &a, const pi &b) -> bool {
return (a.first == b.first ? a.second > b.second : a.first < b.first);
});
vector<int> lis(n + 1, INT_MAX);
lis[0] = 0;
vector<vector<pi>> candies_caught(n + 1);
for (int i = 0; i < n; i++) {
int r_point = candies[i].second;
int l = 0; // Condition: lis[l] < r_point
int r = n; // Condition: lis[r] >= r_point
while (r > l + 1) {
int mid = (l + r) / 2;
if (lis[mid] < r_point) {
l = mid;
} else {
r = mid;
}
}
lis[l + 1] = r_point;
// Candies with the same lis length can be caught by the same wagon
candies_caught[l + 1].push_back(candies[i]);
}
int ans = 0;
while (ans < n && lis[ans + 1] != INT_MAX) { ans++; }
cout << ans << "\n";
// for (int len = 1; len <= ans; len++) {
// for (pi c : candies_caught[len]) {
// int s = (long long)(c.first + c.second) / 2;
// int t = (long long)(c.second - c.first) / 2;
//
// cout << s << " " << t << " " << len << "\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... |