Submission #1312220

#TimeUsernameProblemLanguageResultExecution timeMemory
1312220aryanLightning Rod (NOI18_lightningrod)C++17
100 / 100
321 ms115956 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; inline int readInt() { int x = 0; char ch = getchar_unlocked(); 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; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; n = readInt(); vector<int> su(n),di(n); stack<int> st; for(int i = 0;i < n;i++){ int x,y; x = readInt(); y = readInt(); su[i] = x + y; di[i] = x - y; bool f = false; while((int) st.size() && di[i] <= di[st.top()]){ st.pop(); f = true; } if((int)st.size() == 0){ st.push(i); }else if(f){ st.push(i); }else{ if(su[st.top()] < su[i]){ st.push(i); } } } cout << (int) st.size() << '\n'; return 0; }
#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...