提出 #4026705


ソースコード 拡げる

#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_

  */

}

提出情報

提出日時
問題 C - Gr-idian MST
ユーザ aajisaka
言語 C++14 (GCC 5.4.1)
得点 500
コード長 1732 Byte
結果 AC
実行時間 35 ms
メモリ 3456 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 30
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
01.txt AC 35 ms 3456 KiB
02.txt AC 35 ms 3456 KiB
03.txt AC 35 ms 3456 KiB
04.txt AC 35 ms 3456 KiB
05.txt AC 35 ms 3456 KiB
06.txt AC 35 ms 3456 KiB
07.txt AC 35 ms 3456 KiB
08.txt AC 35 ms 3456 KiB
09.txt AC 35 ms 3456 KiB
10.txt AC 35 ms 3456 KiB
11.txt AC 30 ms 3456 KiB
12.txt AC 30 ms 3456 KiB
13.txt AC 25 ms 3456 KiB
14.txt AC 34 ms 3456 KiB
15.txt AC 34 ms 3456 KiB
16.txt AC 18 ms 1792 KiB
17.txt AC 18 ms 1792 KiB
18.txt AC 18 ms 1792 KiB
19.txt AC 18 ms 1792 KiB
20.txt AC 16 ms 3456 KiB
21.txt AC 25 ms 3456 KiB
22.txt AC 25 ms 3456 KiB
23.txt AC 22 ms 3456 KiB
24.txt AC 24 ms 3456 KiB
25.txt AC 1 ms 256 KiB
26.txt AC 1 ms 256 KiB
27.txt AC 1 ms 256 KiB
28.txt AC 1 ms 256 KiB
s1.txt AC 1 ms 256 KiB
s2.txt AC 1 ms 256 KiB