답안 #671016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671016 2022-12-11T16:57:12 Z Do_you_copy 학교 설립 (IZhO13_school) C++17
15 / 100
95 ms 10784 KB
/*
    I find it wholesome to be alone the greater part of the time.
    To be in company, even with the best, is soon wearisome and dissipating.
    I love to be alone.
    I never found the companion that was so companionable as solitude.
*/
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
mt19937_64 Rand(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 3e5 + 10;
//const int Mod = 1e9 + 7;
//const int inf =
int n, m, k;
pii a[maxN];
bool visited[maxN];
void Init(){
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i){
        cin >> a[i].fi >> a[i].se;
    }
    ll ans = 0;
    sort(a + 1, a + n + 1, greater <pii>());
    priority_queue <int> PQ;
    priority_queue <pii> PQ1, PQ2;
    for (int i = 1; i <= m; ++i){
        ans += a[i].fi;
        PQ.push({a[i].se - a[i].fi});
        visited[i] = 1;
    }
    for (int i = m + 1; i <= n; ++i){
        PQ1.push({a[i].se, i});
        PQ2.push({a[i].fi, i});
    }
    for (int i = 1; i <= k; ++i){
        while (!PQ1.empty() && visited[PQ1.top().se]) PQ1.pop();
        while (!PQ2.empty() && visited[PQ2.top().se]) PQ2.pop();
        auto u = PQ.top() + PQ2.top().fi;
        auto v = PQ1.top();
        if (u >= v.fi){
            ans += u;
            PQ.pop();
            int j = PQ2.top().se;
            visited[j] = 1;
            PQ.push(a[j].fi - a[j].se);
            PQ2.pop();
        }
        else{
            ans += v.fi;
            visited[v.se] = 1;
            PQ1.pop();
        }
    }
    cout << ans;
}

#define debug
#define taskname "test"
signed main(){
    faster
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
        timeout.close();
        #ifndef debug
        cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
        #endif // debug
    }
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 2 ms 468 KB Output isn't correct
8 Incorrect 2 ms 400 KB Output isn't correct
9 Incorrect 2 ms 472 KB Output isn't correct
10 Incorrect 2 ms 468 KB Output isn't correct
11 Incorrect 2 ms 596 KB Output isn't correct
12 Incorrect 2 ms 596 KB Output isn't correct
13 Incorrect 9 ms 1236 KB Output isn't correct
14 Incorrect 25 ms 3536 KB Output isn't correct
15 Incorrect 45 ms 6588 KB Output isn't correct
16 Incorrect 93 ms 7140 KB Output isn't correct
17 Incorrect 78 ms 8960 KB Output isn't correct
18 Incorrect 76 ms 9372 KB Output isn't correct
19 Incorrect 84 ms 9772 KB Output isn't correct
20 Incorrect 95 ms 10784 KB Output isn't correct