답안 #336134

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336134 2020-12-14T19:54:29 Z ScarletS 학교 설립 (IZhO13_school) C++17
100 / 100
123 ms 8324 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
using namespace std;

bool cmp(pii& a, pii& b)
{
    return a.f-a.s<b.f-b.s;
}

ll max(ll a, ll b)
{
    if (a>b)
        return a;
    return b;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,M,S;
    cin>>n>>M>>S;
    pii a[n+1];
    for (int i=1;i<=n;++i)
        cin>>a[i].f>>a[i].s;
    sort(a+1,a+n+1,cmp);
    ll sum=0,ans=0,b[n+2],c[n+2];
    priority_queue<int,vector<int>,greater<int>> p,q;
    for (int i=1;i<=n;++i)
    {
        sum+=a[i].s;
        p.push(a[i].s);
        if (i>S)
        {
            sum-=p.top();
            p.pop();
        }
        b[i]=sum;
    }
    sum=0;
    for (int i=n;i;--i)
    {
        sum+=a[i].f;
        q.push(a[i].f);
        if (n-i>=M)
        {
            sum-=q.top();
            q.pop();
        }
        c[i]=sum;
    }
    b[0]=c[n+1]=0;
    b[n+1]=b[n];
    c[0]=c[1];
    for (int i=0;i<=n;++i)
        ans=max(ans,b[i]+c[i+1]);
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 14 ms 1388 KB Output is correct
14 Correct 33 ms 2412 KB Output is correct
15 Correct 62 ms 4076 KB Output is correct
16 Correct 73 ms 5416 KB Output is correct
17 Correct 89 ms 6404 KB Output is correct
18 Correct 100 ms 6768 KB Output is correct
19 Correct 110 ms 7408 KB Output is correct
20 Correct 123 ms 8324 KB Output is correct