結果

問題 No.1597 Matrix Sort
ユーザー N___haraN___hara
提出日時 2021-07-09 22:10:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 1,500 ms
コード長 1,187 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 202,952 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 09:19:00
合計ジャッジ時間 4,499 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 61 ms
4,376 KB
testcase_04 AC 61 ms
4,380 KB
testcase_05 AC 63 ms
4,376 KB
testcase_06 AC 66 ms
4,376 KB
testcase_07 AC 65 ms
4,380 KB
testcase_08 AC 43 ms
4,376 KB
testcase_09 AC 41 ms
4,380 KB
testcase_10 AC 23 ms
4,380 KB
testcase_11 AC 26 ms
4,376 KB
testcase_12 AC 35 ms
4,376 KB
testcase_13 AC 55 ms
4,380 KB
testcase_14 AC 60 ms
4,376 KB
testcase_15 AC 28 ms
4,376 KB
testcase_16 AC 38 ms
4,376 KB
testcase_17 AC 41 ms
4,376 KB
testcase_18 AC 61 ms
4,380 KB
testcase_19 AC 44 ms
4,380 KB
testcase_20 AC 38 ms
4,380 KB
testcase_21 AC 34 ms
4,380 KB
testcase_22 AC 31 ms
4,380 KB
testcase_23 AC 29 ms
4,376 KB
testcase_24 AC 17 ms
4,380 KB
testcase_25 AC 15 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n,p;
  long long k;
  cin >> n >> k >> p;
  vector<int> a(n);
  vector<int> b(n);
  for (int i=0;i<n;i++) {
    cin >> a[i];
  }
  for (int i=0;i<n;i++) {
    cin >> b[i];
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  int i = 0;
  int j = n-1;
  long long pcnt = 0;
  while (i < n && j >= 0) {
    if (a[i]+b[j] < p) {
      pcnt += j+1;
      i++;
    }
    else {
      j--;
    }
  }
  int l = 0;
  int h = p-1;
  int las = h;
  while (l <= h) {
    int now = (l+h)/2;
    i = 0;
    j = n-1;
    long long ncnt = 0;
    while (i < n && j >= 0) {
      if (a[i]+b[j] <= now) {
        ncnt += j+1;
        i++;
      }
      else {
        j--;
      }
    }
    i = 0;
    j = n-1;
    long long npcnt = 0;
    while (i < n && j >= 0) {
      if (a[i]+b[j] <= now+p) {
        ncnt += j+1;
        i++;
      }
      else {
        j--;
      }
    }
    long long cnt = npcnt-pcnt+ncnt;
    //cout << now << ' ' << cnt << endl;
    if (cnt >= k) {
      las = now;
      h = now-1;
    }
    else {
      l = now+1;
    }
  }
  cout << las << endl;
}
0