# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1060640 | 2024-08-15T20:10:41 Z | oviyan_gandhi | Lightning Rod (NOI18_lightningrod) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; inline int readInt() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = _getchar_nolock(); while (ch >= '0' && ch <= '9'){ x = (x << 3) + (x << 1) + ch - '0'; ch = _getchar_nolock(); } return x; } int X[10000000], Y[10000000]; bool use[10000000]; // whether i contains j bool contains(int i, int j){ return abs(X[i] - X[j]) <= (Y[i] - Y[j]); } int main(){ int N = readInt(); for(int i = 0; i < N; i++) { X[i] = readInt(); Y[i] = readInt(); use[i] = true; } stack<int> s; for (int i = 0; i < N; i++){ while (!s.empty() && !contains(s.top(), i)) s.pop(); if (!s.empty()) use[i] = false; s.push(i); } while (!s.empty()) s.pop(); for (int i = N-1; i >= 0; i--){ while (!s.empty() && !contains(s.top(), i)) s.pop(); if (!s.empty()) use[i] = false; s.push(i); } cout << accumulate(use, use+N, 0) << '\n'; return 0; }