Submission #520028

#TimeUsernameProblemLanguageResultExecution timeMemory
520028sumit_kk10Lightning Rod (NOI18_lightningrod)C++17
100 / 100
912 ms262144 KiB
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define pb push_back #define ll long long #define F first #define S second using namespace std; const int N = 1e7 + 5, MOD = 1e9 + 7; inline int readInt() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ch = getchar_unlocked(); while (ch >= '0' && ch <= '9'){ x = (x << 3) + (x << 1) + ch - '0'; ch = getchar_unlocked(); } return x; } void solve(){ int n = readInt(); pair<int, int> a[n]; for(int i = 0; i < n; ++i){ a[i].F = readInt(); a[i].S = readInt(); } sort(a, a + n); int pre_max[n], suf_mn[n + 1]; pre_max[0] = a[0].F + a[0].S; for(int i = 1; i < n; ++i) pre_max[i] = max(pre_max[i - 1], a[i].F + a[i].S); suf_mn[n - 1] = a[n - 1].F - a[n - 1].S; for(int i = n - 2; i >= 0; --i) suf_mn[i] = min(suf_mn[i + 1], a[i].F - a[i].S); int ans = (suf_mn[1] > (a[0].F - a[0].S)); suf_mn[n] = INT_MAX; for(int i = 1; i < n; ++i){ if((pre_max[i - 1] >= (a[i].F + a[i].S)) or (suf_mn[i + 1] <= (a[i].F - a[i].S))) continue; ++ans; } cout << ans << '\n'; } int main(){ fast; int 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...