Submission #703163

# Submission time Handle Problem Language Result Execution time Memory
703163 2023-02-26T10:11:03 Z LucaLucaM Sails (IOI07_sails) C++17
100 / 100
48 ms 5436 KB
#include <bits/stdc++.h>

using namespace std;

/**
luam fiecare sail in ordine crescatoare dupa inaltime:
luam cele mai putin frecvente k inaltimi
adunam la raspuns
**/

const int NMAX = 1e5;

struct sail
{
    int x, y;

    bool operator < (const sail aux) const
    {
        if (x == aux.x)
            return y > aux.y;
        return x < aux.x;
    }
};

sail a[NMAX + 5];

int f[NMAX + 5];

multiset<pair<int, int>>st;

/**
tinem diferenta intre doua consecutive
**/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    for (int i=1; i<=n; i++)
        cin >> a[i].x >> a[i].y;

    sort(a+1, a+n+1);

    multiset<int>st;

    st.insert(0);

    for (int i=1; i<=n; i++)
    {
        st.insert(a[i].x);

        auto p = st.upper_bound(a[i].x-a[i].y);
        auto q = prev(p);

        int nxt = *p + *q - a[i].x + a[i].y;
        if (q != st.begin())
            st.erase(q);
        st.insert(nxt);
        st.erase(p);
    }

    long long ans = 0, cnt = 0;
    for (auto it = st.end(); it-- != st.begin(); cnt++) // in ordine inversa
        ans += cnt * *it;

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 13 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3460 KB Output is correct
2 Correct 32 ms 2500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 5436 KB Output is correct
2 Correct 25 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3404 KB Output is correct
2 Correct 43 ms 2340 KB Output is correct