답안 #441208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441208 2021-07-04T16:11:14 Z parsabahrami 학교 설립 (IZhO13_school) C++17
15 / 100
248 ms 19044 KB
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 3e5 + 10, MOD = 1e9 + 7;
int A[N], B[N], ord[N], M[N], m, s, n; set<pii, greater<pii>> st1, st2;

int main() {
    scanf("%d%d%d", &n, &m, &s);
    for (int i = 1; i <= n; i++) 
        scanf("%d%d", &A[i], &B[i]);
    iota(ord + 1, ord + n + 1, 1);
    sort(ord + 1, ord + n + 1, [&] (int a, int b) { return A[a] > A[b]; });
    ll sum = 0;
    for (int i = 1; i <= m; i++) {
        st1.insert({B[ord[i]] - A[ord[i]], ord[i]});
        sum += A[ord[i]];
    }
    for (int i = m + 1; i <= n; i++) 
        st2.insert({B[ord[i]], ord[i]});
    int ptr = m + 1;
    for (int i = 1; i <= s; i++) {
        while (ptr <= n && M[ord[ptr]]) ptr++;
        int c1 = (SZ(st1) ? st1.begin()->F + A[ord[ptr]] : -MOD),
            c2 = (SZ(st2) ? st2.begin()->F : -MOD);
        if (c2 > c1) {
            M[st2.begin()->S] = 1, sum += c2;
            st2.erase(st2.begin());
        } else {
            M[st1.begin()->S] = 1, sum += c1;
            st1.erase(st1.begin());
            st1.insert({B[ord[ptr]] - A[ord[ptr]], ord[ptr]});
        }
    }
    printf("%lld\n", sum);
    return 0;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%d%d%d", &n, &m, &s);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
school.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%d%d", &A[i], &B[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Incorrect 0 ms 296 KB Output isn't correct
6 Incorrect 1 ms 332 KB Output isn't correct
7 Incorrect 3 ms 632 KB Output isn't correct
8 Incorrect 3 ms 588 KB Output isn't correct
9 Incorrect 3 ms 588 KB Output isn't correct
10 Incorrect 3 ms 572 KB Output isn't correct
11 Incorrect 4 ms 588 KB Output isn't correct
12 Incorrect 3 ms 588 KB Output isn't correct
13 Incorrect 22 ms 2628 KB Output isn't correct
14 Incorrect 50 ms 5188 KB Output isn't correct
15 Incorrect 118 ms 10244 KB Output isn't correct
16 Incorrect 146 ms 11584 KB Output isn't correct
17 Incorrect 172 ms 14020 KB Output isn't correct
18 Incorrect 180 ms 15368 KB Output isn't correct
19 Incorrect 207 ms 16552 KB Output isn't correct
20 Incorrect 248 ms 19044 KB Output isn't correct