# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
548730 | jack715 | Lightning Rod (NOI18_lightningrod) | C++14 | 2016 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second
using namespace std;
bool protect(pair<int, int>& a, pair<int, int>& b) {
return (abs(a.ff-b.ff) <= a.ss-b.ss);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, a, b, ans = 1;
cin >> n;
stack<pair<int, int> > select;
vector<pair<int, int> > nums(n), prot(n);
for (int i = 0; i < n; i++) {
cin >> nums[i].ff >> nums[i].ss;
prot[i] = nums[i];
}
select.push(nums[0]);
for (int i = 1; i < n; i++) {
if (!select.empty() && protect(select.top(), nums[i]))
continue;
while (!select.empty() && protect(nums[i], select.top())) {
ans--;
select.pop();
}
ans++;
select.push(nums[i]);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | 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... |