제출 #335365

#제출 시각아이디문제언어결과실행 시간메모리
335365ncduy0303Lightning Rod (NOI18_lightningrod)C++17
100 / 100
556 ms192660 KiB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

inline int readInt() {
    int x = 0;
    char ch = getchar_unlocked();
    while (ch < '0' || ch > '9') ch = getchar_unlocked();
    while ('0' <= ch && ch <= '9') {
        x = (x << 3) + (x << 1) + ch - '0';
        ch = getchar_unlocked();
    }
    return x;
}

void solve() {
    int n = readInt();
    stack<ar<int,2>> st;
    while (n--) { // increasing x
        int x = readInt(), y = readInt();
        bool add = true;
        while (st.size()) {
            auto [tx, ty] = st.top();
            if (x - tx <= ty - y) {
                add = false;
                break;
            }
            if (x - tx <= y - ty) st.pop();
            else break;
        }
        if (add) st.push({x, y});
    }
    cout << st.size() << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << 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...