Submission #1726104


Source Code Expand

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

int W, H;
vector<int> P, Q;

int main()
{
    ll ans = 0;
    ll edge = 0;
    cin >> W >> H;
    REP(i, W) {
        int tmp;
        cin >> tmp;
        P.push_back(tmp);
        ans += tmp;
        edge++;
    }
    REP(i, H) {
        int tmp;
        cin >> tmp;
        Q.push_back(tmp);
        ans += tmp;
        edge++;
    }
    //printf("ans: %lld\n", ans);
    //printf("edge: %lld\n", edge);
    SORT(P);
    SORT(Q);
    int p_ind = 0, q_ind = 0;
    while(edge < (W+1) * (H+1) - 1) {
        if(P[p_ind] < Q[q_ind]) {
            ans += (H - q_ind) * P[p_ind];
            //printf("P[%d]: %d\n", p_ind, P[p_ind]);
            p_ind++;
            edge += (H - q_ind > 0) ? (H - q_ind) : 1;
        } else {
            ans += (W - p_ind) * Q[q_ind];
            //printf("Q[%d]: %d\n", q_ind, Q[q_ind]);
            q_ind++;
            edge += (W - p_ind > 0) ? (W - p_ind) : 1;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Submission Info

Submission Time
Task C - Gr-idian MST
User VTR
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1419 Byte
Status WA
Exec Time 112 ms
Memory 1400 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 6
WA × 24
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt WA 112 ms 1396 KB
02.txt WA 109 ms 1400 KB
03.txt WA 111 ms 1400 KB
04.txt WA 109 ms 1400 KB
05.txt WA 111 ms 1400 KB
06.txt WA 109 ms 1400 KB
07.txt WA 110 ms 1400 KB
08.txt WA 109 ms 1400 KB
09.txt WA 110 ms 1400 KB
10.txt WA 109 ms 1400 KB
11.txt WA 106 ms 1400 KB
12.txt WA 103 ms 1400 KB
13.txt WA 101 ms 1400 KB
14.txt WA 109 ms 1400 KB
15.txt WA 110 ms 1400 KB
16.txt WA 55 ms 892 KB
17.txt WA 56 ms 892 KB
18.txt WA 55 ms 892 KB
19.txt WA 56 ms 892 KB
20.txt WA 39 ms 1400 KB
21.txt WA 75 ms 1400 KB
22.txt WA 74 ms 1400 KB
23.txt WA 75 ms 1400 KB
24.txt WA 109 ms 1400 KB
25.txt AC 1 ms 256 KB
26.txt AC 1 ms 256 KB
27.txt AC 1 ms 256 KB
28.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB