# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
235536 | 2020-05-28T12:50:39 Z | golazcc83 | 학교 설립 (IZhO13_school) | C++14 | 175 ms | 22904 KB |
#include <iostream> #include <algorithm> #define MINF -1000000000000000000 using namespace std; typedef long long ll; const int MAXN = 300001; int N, M, S; struct student { ll a, b; int idx; } A[MAXN], B[MAXN]; bool compA(const student &s1, const student &s2) { if(s1.a != s2.a) return s1.a > s2.a; return s1.b < s2.b; } bool compB(const student &s1, const student &s2) { if(s1.b != s2.b) return s1.b > s2.b; return s1.a < s2.a; } ll An[MAXN], Bn[MAXN]; bool v[MAXN]; int main() { scanf("%d %d %d", &N, &M, &S); for(int i = 0; i < N; ++i) { scanf("%lld %lld", &An[i], &Bn[i]); A[i].a = B[i].a = An[i]; A[i].b = B[i].b = Bn[i]; A[i].idx = B[i].idx = i; } sort(A, A + N, compA); sort(B, B + N, compB); A[N].a = A[N].b = B[N].a = B[N].b = MINF; fill(v, v + N + 1, false); ll res = 0; int ia = 0, ib = 0; int ta = 0, tb = 0; while(ta != M || tb != S) { while(ta != M) { if(!v[A[ia].idx]) { res += A[ia].a; v[A[ia].idx] = true; ++ia; ++ta; continue; } ll nxtA = Bn[A[ia].idx] + A[ia + 1].a; ll nxtB = B[ib].b + A[ia].a; if(nxtA >= nxtB) { ++ia; continue; } res += A[ia].a - Bn[A[ia].idx]; --tb; ++ta; ++ia; } while(tb != S) { if(!v[B[ib].idx]) { res += B[ib].b; v[B[ib].idx] = true; ++ib; ++tb; continue; } ll nxtA = An[B[ib].idx] + B[ib + 1].b; ll nxtB = A[ia].a + B[ib].b; if(nxtA >= nxtB) { ++ib; continue; } res += B[ib].b - An[B[ib].idx]; --ta; ++tb; ++ib; } } printf("%lld\n", res); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 384 KB | Output isn't correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Incorrect | 4 ms | 384 KB | Output isn't correct |
4 | Incorrect | 5 ms | 384 KB | Output isn't correct |
5 | Incorrect | 5 ms | 384 KB | Output isn't correct |
6 | Incorrect | 5 ms | 512 KB | Output isn't correct |
7 | Incorrect | 6 ms | 640 KB | Output isn't correct |
8 | Incorrect | 7 ms | 640 KB | Output isn't correct |
9 | Incorrect | 8 ms | 768 KB | Output isn't correct |
10 | Incorrect | 7 ms | 632 KB | Output isn't correct |
11 | Incorrect | 7 ms | 768 KB | Output isn't correct |
12 | Incorrect | 7 ms | 768 KB | Output isn't correct |
13 | Incorrect | 24 ms | 3072 KB | Output isn't correct |
14 | Incorrect | 45 ms | 6144 KB | Output isn't correct |
15 | Incorrect | 102 ms | 12152 KB | Output isn't correct |
16 | Incorrect | 106 ms | 13664 KB | Output isn't correct |
17 | Incorrect | 129 ms | 16760 KB | Output isn't correct |
18 | Incorrect | 138 ms | 18424 KB | Output isn't correct |
19 | Incorrect | 155 ms | 19800 KB | Output isn't correct |
20 | Incorrect | 175 ms | 22904 KB | Output isn't correct |