Submission #1162979


Source Code Expand

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>

typedef long long ll;
#define fi first
#define se second

int W, H;
ll P[112345];
ll Q[112345];
ll ans;

using namespace std;

int main(){
  
  cin>>W>>H;
  
  int i;
  
  for( i = 0; i < W; i++ ){
    scanf("%d", P+i);
  }
  
  P[W] = 112345678;
  
  for( i = 0; i < H; i++ ){
    scanf("%d", Q+i);
  }
  
  Q[H] = 112345678;
  
  ll numP, numQ;
  
  numP = H+1;
  numQ = W+1;
  
  int idxP;
  int idxQ;
  
  idxQ = 0;
  idxP = 0;
  
  sort( P, P+W );
  sort( Q, Q+H );
  
  ans = 0;
  
  
  while( idxP != W || idxQ != H ){
    
    if( P[idxP] > Q[idxQ] ){
      ans += Q[idxQ]*numQ;
      idxQ++;
      numP--;
    }
    else{
      ans += P[idxP]*numP;
      idxP++;
      numQ--;
    }
    
    //printf("%d %d\n",idxP, idxQ );
  }
  
  cout<<ans<<endl;
  
  return 0;
}

Submission Info

Submission Time
Task C - Gr-idian MST
User Ice_in_juice
Language C++14 (GCC 5.4.1)
Score 500
Code Size 944 Byte
Status AC
Exec Time 36 ms
Memory 1792 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:25:20: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘ll* {aka long long int*}’ [-Wformat=]
     scanf("%d", P+i);
                    ^
./Main.cpp:31:20: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘ll* {aka long long int*}’ [-Wformat=]
     scanf("%d", Q+i);
                    ^
./Main.cpp:25:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", P+i);
                     ^
./Main.cpp:31:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", Q+i);
                     ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 30
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 AC 36 ms 1792 KB
02.txt AC 36 ms 1792 KB
03.txt AC 36 ms 1792 KB
04.txt AC 36 ms 1792 KB
05.txt AC 36 ms 1792 KB
06.txt AC 36 ms 1792 KB
07.txt AC 36 ms 1792 KB
08.txt AC 36 ms 1792 KB
09.txt AC 36 ms 1792 KB
10.txt AC 36 ms 1792 KB
11.txt AC 31 ms 1792 KB
12.txt AC 31 ms 1792 KB
13.txt AC 27 ms 1792 KB
14.txt AC 36 ms 1792 KB
15.txt AC 35 ms 1792 KB
16.txt AC 18 ms 1024 KB
17.txt AC 18 ms 1024 KB
18.txt AC 18 ms 1024 KB
19.txt AC 18 ms 1024 KB
20.txt AC 19 ms 1792 KB
21.txt AC 27 ms 1792 KB
22.txt AC 27 ms 1792 KB
23.txt AC 23 ms 1792 KB
24.txt AC 26 ms 1792 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