제출 #1139843

#제출 시각아이디문제언어결과실행 시간메모리
1139843fcmalkcinLightning Rod (NOI18_lightningrod)C++20
100 / 100
418 ms159084 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
stack<pair<ll,ll>> st;
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;
}
signed main(){
    ll n;
    n = readInt();
    for (ll i = 0;i<n;i++){
        ll x,y;
        x = readInt(); 
        y = readInt();
        bool checkAdd = true;
        while (true){
            if (st.size() == 0){
                st.push({x,y});
                checkAdd = false;
                break;
            }
            ll sx = st.top().first, sy = st.top().second;
            if (x-sx<=sy-y) {
                checkAdd = false;
                break;
            }
            else if (x-sx <=y-sy) { 
                st.pop();
                
            }
            else {
                break;
            }
        }
        if (checkAdd) st.push({x, y});
    }
    
    cout<<st.size()<<endl;
}
#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...