Submission #921517

#TimeUsernameProblemLanguageResultExecution timeMemory
921517BzslayedLightning Rod (NOI18_lightningrod)C++17
100 / 100
343 ms193136 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define coutpair(p) cout << p.first << " " << p.second << "\n"

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

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

stack<pii> s;
int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);

    int n = readInt();
    for (int i=0; i<n; i++){
        int x = readInt();
        int y = readInt();
        bool add = true;
        while (s.size()) {
            int fx = s.top().first;
            int fy = s.top().second;
            if (x-fx <= fy-y) {
                add = false;
                break;
            }
            if (x-fx <= y-fy) {
                s.pop();
            } 
            else break;
        }
        if (add) s.push({x, y});
    }
    cout << s.size();

    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...