답안 #1034159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034159 2024-07-25T10:12:44 Z vjudge1 학교 설립 (IZhO13_school) C++17
20 / 100
72 ms 14212 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define fi first
#define se second
using namespace std;

int n, m, s;
const int maxn = 1e6 + 3;
const int inf = 1e9;
pll p[maxn + 3];
priority_queue<int, vector<int>, greater<int>>pq1, pq2;
ll l[maxn + 3], r[maxn + 3], ans;

bool cmp(pll a, pll b)
{
    return a.fi - a.se < b.fi - b.se;
}

int main()
{
  //  freopen("SCHOOL.INP", "r", stdin);
 //   freopen("SCHOOL.OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m >> s;
    for(int i = 1; i <= n; i++)
    {
        cin >> p[i].fi >> p[i].se;
    }
    sort(p + 1, p + n + 1, cmp);
    /*for(int i = 1; i <= n; i++)
    {
        cout << p[i].first << ' ' << p[i].second << '\n';
    } cout << '\n';*/
    for(int i = 1; i <= s; i++)
    {
        pq1.push(p[i].se);
        ans += p[i].se;
        l[i] = ans;
    }
    for(int i = s + 1; i <= n; i++)
    {
        if(p[i].se > pq1.top() && !pq1.empty())
        {
            ans = ans + p[i].se - pq1.top();
        }
        l[i] = ans;
    }
    ll ans = 0;
    for(int i = n; i >= n - m + 1; i--)
    {
        pq2.push(p[i].fi);
        ans += p[i].fi;
        r[i] = ans;
    }
    //cout << ans;
    for(int i = n - m; i >= 1; i--)
    {
        if(p[i].fi > pq2.top() && !pq2.empty())
        {
            ans  = ans + p[i].fi - pq2.top();
        }
        r[i] = ans;
    }
     ans = -inf;
    for(int i = 1; i < n; i++)
    {
        ans = max(ans, l[i] + r[i + 1]);
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Correct 0 ms 472 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 1 ms 600 KB Output isn't correct
8 Correct 1 ms 492 KB Output is correct
9 Incorrect 1 ms 604 KB Output isn't correct
10 Incorrect 2 ms 556 KB Output isn't correct
11 Incorrect 1 ms 488 KB Output isn't correct
12 Incorrect 1 ms 604 KB Output isn't correct
13 Incorrect 8 ms 2028 KB Output isn't correct
14 Incorrect 19 ms 3932 KB Output isn't correct
15 Incorrect 34 ms 7244 KB Output isn't correct
16 Correct 45 ms 8716 KB Output is correct
17 Incorrect 44 ms 10564 KB Output isn't correct
18 Incorrect 53 ms 11528 KB Output isn't correct
19 Incorrect 55 ms 12432 KB Output isn't correct
20 Incorrect 72 ms 14212 KB Output isn't correct