Submission #1262562

#TimeUsernameProblemLanguageResultExecution timeMemory
1262562phtungLightning Rod (NOI18_lightningrod)C++20
70 / 100
1102 ms263240 KiB
#include <bits/stdc++.h>

using namespace std;

#define name "IO"
#define int long long

const int inf = 1e9;
const int maxn = 1e7 + 5;
int n;

void solve()
{
    cin >> n;

    int one = 0;
    vector<pair<int,int>> p;
    for(int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        one += (y == 1);
        p.push_back({x, y});
    }

    if(one == n)
    {
        cout << n << "\n";
        return;
    }

    stack<pair<int,int>> st;
    int l = p[0].first, r = p.back().first;

    auto check = [&](int x, int y) -> bool{
        auto [i, j] = st.top();

        if(x - y <= i - j && x + y >= i + j) return 1;
        return 0;
    };

    auto ok = [&](int x, int y) -> bool {
        auto [i, j] = st.top();
        if(x + y > i + j) return 1;
        return 0;
    };

    for(int i = 0; i < p.size(); i++)
    {
        auto [x, y] = p[i];

        while(!st.empty() && check(x, y)) st.pop();

        if(st.empty() || ok(x, y)) st.push({x, y});
    }

    cout << st.size() << "\n";
}

signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t start = clock();

    int t = 1;

    while(t--) solve();

    std::cerr << "Time: " << clock() - start << "ms\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...