Submission #1311728

#TimeUsernameProblemLanguageResultExecution timeMemory
1311728samarthkulkarniLightning Rod (NOI18_lightningrod)C++17
100 / 100
272 ms79620 KiB
#include <bits/stdc++.h>
using namespace std;
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;
}

stack<pair<int, int>> s;
int main()
{
    int N = readInt();
    for (int i = 0; i < N; i++)
    {
        int x = readInt(), y = readInt();
        bool add = true;
        while (s.size())
        {
            auto [px, py] = s.top();
            // * check if last rod covers current building
            if (x - px <= py - y)
            {
                add = 0; // * no need to add a rod
                break;
            }
            if (x - px <= y - py) // * ccheck if last rod is useless
                s.pop();
            else
                break;
        }

        if (add)
            s.push({x,y});
    }

    cout << s.size();
    // write code here
    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...