Submission #171684

# Submission time Handle Problem Language Result Execution time Memory
171684 2019-12-30T03:42:15 Z SamAnd Schools (IZhO13_school) C++17
95 / 100
127 ms 11376 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const long long INF = 1000000009000000009;
struct ban
{
    int m, s;
};
bool operator<(const ban& a, const ban& b)
{
    return (a.m - a.s) > (b.m - b.s);
}

int n, m, s;
ban a[N];

long long pp[N], ss[N];

int main()
{
    scanf("%d%d%d", &n, &m, &s);
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", &a[i].m, &a[i].s);
    sort(a + 1, a + n + 1);
    long long sum = 0;
    priority_queue<int> q;
    for (int i = 1; i <= n; ++i)
    {
        if (q.size() < m)
        {
            q.push(-a[i].m);
            sum += a[i].m;
        }
        else
        {
            if (a[i].m > -q.top())
            {
                sum += q.top();
                q.pop();
                q.push(-a[i].m);
                sum += a[i].m;
            }
        }
        if (q.size() < m)
            pp[i] = -INF;
        else
            pp[i] = sum;
    }
    sum = 0;
    while (!q.empty())
        q.pop();
    for (int i = n; i >= 1; --i)
    {
        if (q.size() < s)
        {
            q.push(-a[i].s);
            sum += a[i].s;
        }
        else
        {
            if (a[i].s > -q.top())
            {
                sum += q.top();
                q.pop();
                q.push(-a[i].s);
                sum += a[i].s;
            }
        }
        if (q.size() < s)
            ss[i] = -INF;
        else
            ss[i] = sum;
    }
    long long ans = -INF;
    for (int i = 1; i < n; ++i)
    {
        ans = max(ans, pp[i] + ss[i + 1]);
    }
    printf("%lld\n", ans);
    return 0;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (q.size() < m)
             ~~~~~~~~~^~~
school.cpp:44:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (q.size() < m)
             ~~~~~~~~~^~~
school.cpp:54:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (q.size() < s)
             ~~~~~~~~~^~~
school.cpp:69:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (q.size() < s)
             ~~~~~~~~~^~~
school.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &n, &m, &s);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
school.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a[i].m, &a[i].s);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 4 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 4 ms 504 KB Output is correct
13 Correct 19 ms 1784 KB Output is correct
14 Correct 34 ms 3192 KB Output is correct
15 Correct 59 ms 6008 KB Output is correct
16 Correct 77 ms 7404 KB Output is correct
17 Correct 96 ms 8560 KB Output is correct
18 Correct 105 ms 9332 KB Output is correct
19 Correct 115 ms 9968 KB Output is correct
20 Correct 127 ms 11376 KB Output is correct