Submission #305051

# Submission time Handle Problem Language Result Execution time Memory
305051 2020-09-22T13:22:33 Z Akashi Sails (IOI07_sails) C++14
40 / 100
1000 ms 3136 KB
#include <bits/stdc++.h>
using namespace std;

const int DIM = 1e5 + 5;

struct poles{
    int h, k;
    bool operator < (const poles &aux)const{
        return h < aux.h;
    }
};

poles a[DIM];

int n;
priority_queue <int, vector <int>, greater <int>> pq;

int main()
{
    #ifdef HOME
    freopen("sails.in", "r", stdin);
    freopen("sails.out", "w", stdout);
    #endif // HOME

    scanf("%d", &n);
    int mx = 0;
    for (int i = 1; i <= n ; ++i) {
        scanf("%d%d", &a[i].h, &a[i].k);
        mx = max(mx, a[i].h);
    }

    sort(a + 1, a + n + 1);
    int now = 1;
    for (int i = 1; i <= n ; ++i) {
        while (now <= a[i].h) {
            pq.push(0);
            ++now;
        }

        vector <int> v;
        while (a[i].k > 0) {
            --a[i].k;

            int x = pq.top();
            pq.pop();
            v.push_back(x + 1);
        }

        for (auto it : v) pq.push(it);
    }

    long long Sol = 0;
    while (!pq.empty()) {
        int x = pq.top();
        if (pq.top() > 0) Sol = Sol + 1LL * (pq.top() - 1) * pq.top() / 2;
        pq.pop();
    }

    printf("%lld", Sol);

    return 0;
}

Compilation message

sails.cpp: In function 'int main()':
sails.cpp:54:13: warning: unused variable 'x' [-Wunused-variable]
   54 |         int x = pq.top();
      |             ^
sails.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
sails.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         scanf("%d%d", &a[i].h, &a[i].k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 384 KB Output is correct
2 Correct 190 ms 1012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 1144 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1085 ms 1528 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 3136 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 2208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 2808 KB Time limit exceeded
2 Halted 0 ms 0 KB -