結果
問題 | No.1597 Matrix Sort |
ユーザー |
![]() |
提出日時 | 2021-07-09 22:10:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 80 ms / 1,500 ms |
コード長 | 1,187 bytes |
コンパイル時間 | 2,130 ms |
コンパイル使用メモリ | 197,592 KB |
最終ジャッジ日時 | 2025-01-22 21:56:04 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#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; }