제출 #47563

#제출 시각아이디문제언어결과실행 시간메모리
47563kuroni학교 설립 (IZhO13_school)C++14
100 / 100
174 ms8152 KiB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

const int N = 300005;

struct SCity
{
    int a, b;
} s[N];
int n;
unsigned int a, b;
long long pre[N], suf[N];
priority_queue<int, vector<int>, greater<int>> pq;

int main()
{
    scanf("%d%u%u", &n, &a, &b);
    for (int i = 1; i <= n; i++)
        scanf("%d%d", &s[i].a, &s[i].b);
    sort(s + 1, s + n + 1, [](const SCity &a, const SCity &b) { return a.a - a.b > b.a - b.b; });
    for (int i = 1; i <= n; i++)
    {
        if (pq.size() < a)
        {
            pre[i] = pre[i - 1] + s[i].a;
            pq.push(s[i].a);
        }
        else if (pq.top() < s[i].a)
        {
            pre[i] = pre[i - 1] - pq.top() + s[i].a;
            pq.pop();
            pq.push(s[i].a);
        }
        else
            pre[i] = pre[i - 1];
    }
    while (!pq.empty())
        pq.pop();
    for (int i = n; i >= 1; i--)
    {
        if (pq.size() < b)
        {
            suf[i] = suf[i + 1] + s[i].b;
            pq.push(s[i].b);
        }
        else if (pq.top() < s[i].b)
        {
            suf[i] = suf[i + 1] - pq.top() + s[i].b;
            pq.pop();
            pq.push(s[i].b);
        }
        else
            suf[i] = suf[i + 1];
    }
    while (!pq.empty())
        pq.pop();
    long long ans = 0;
    for (int i = 0; i <= n; i++)
        ans = max(ans, pre[i] + suf[i + 1]);
    printf("%lld", ans);
}

컴파일 시 표준 에러 (stderr) 메시지

school.cpp: In function 'int main()':
school.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%u%u", &n, &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
school.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &s[i].a, &s[i].b);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...