Submission #4026705


Source Code Expand

#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);

// use unordered_map to save memory usage
unordered_map<int, int> mp;
int get(int x) {
  int ret = mp[x];
  if (ret == 0) {
    mp.erase(x);
    ret = INT_MAX/2;
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int w, h; cin >> w >> h;
  vector<ll> p(w);
  rep(i, w) {
    cin >> p[i];
  }
  vector<ll> q(h);
  rep(i, h) {
    cin >> q[i];
  }
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  
  vector<ll> sump(w+1);
  vector<ll> sumq(h+1);
  rep(i, w) {
    sump[i+1] = sump[i] + p[i];
  }
  rep(i, h) {
    sumq[i+1] = sumq[i] + q[i];
  }

  int pos = 0;
  ll ans = sump[w] + sumq[h];
  rep(i, w) {
    while (pos < h && p[i] > q[pos]) {
      pos++;
    }
    ans += sumq[pos] + p[i]*(h-pos);
  }

  cout << ans << endl;
  /*

  _  _  _
  2  2  2
  __3__5_
     7
  __3__5_

  */

}

Submission Info

Submission Time
Task C - Gr-idian MST
User aajisaka
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1732 Byte
Status AC
Exec Time 35 ms
Memory 3456 KB

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 35 ms 3456 KB
02.txt AC 35 ms 3456 KB
03.txt AC 35 ms 3456 KB
04.txt AC 35 ms 3456 KB
05.txt AC 35 ms 3456 KB
06.txt AC 35 ms 3456 KB
07.txt AC 35 ms 3456 KB
08.txt AC 35 ms 3456 KB
09.txt AC 35 ms 3456 KB
10.txt AC 35 ms 3456 KB
11.txt AC 30 ms 3456 KB
12.txt AC 30 ms 3456 KB
13.txt AC 25 ms 3456 KB
14.txt AC 34 ms 3456 KB
15.txt AC 34 ms 3456 KB
16.txt AC 18 ms 1792 KB
17.txt AC 18 ms 1792 KB
18.txt AC 18 ms 1792 KB
19.txt AC 18 ms 1792 KB
20.txt AC 16 ms 3456 KB
21.txt AC 25 ms 3456 KB
22.txt AC 25 ms 3456 KB
23.txt AC 22 ms 3456 KB
24.txt AC 24 ms 3456 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