Submission #692713

#TimeUsernameProblemLanguageResultExecution timeMemory
692713zeroesandonesLightning Rod (NOI18_lightningrod)C++17
100 / 100
1726 ms225040 KiB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "

#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back

void solve()
{
    int n;
    cin >> n;

    int x[n], y[n];
    FOR(i, 0, n) {
        cin >> x[i] >> y[i];
    }

    stack<pair<int, int>> s;
    for(int i = 0; i < n; ++i) {
        bool add = true;
        while(!s.empty()) {
            auto [nx, ny] = s.top();
            if(x[i] - nx <= ny - y[i]) {
                add = false;
                break;
            }

            if(x[i] - nx <= y[i] - ny)
                s.pop();
            else
                break;
        }
        if(add)
            s.push({x[i], y[i]});
    }

    cout << s.size() << nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...