結果
| 問題 | No.1597 Matrix Sort |
| コンテスト | |
| ユーザー |
seven_three
|
| 提出日時 | 2021-07-09 23:17:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,176 bytes |
| 記録 | |
| コンパイル時間 | 964 ms |
| コンパイル使用メモリ | 99,916 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-01 18:19:16 |
| 合計ジャッジ時間 | 7,641 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 2 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long n, k, p;
vector<long long> a, b;
bool solve(long long x) {
long long sum = 0;
for (int i = 0; i < n; i++) {
long long l1 = x - a[i];
auto itr = upper_bound(b.begin(), b.end(), l1);
sum += int(itr - b.begin());
long long l2 = p - a[i];
long long r1 = p + x - a[i];
auto itr1 = lower_bound(b.begin(), b.end(), l2);
auto itr2 = upper_bound(b.begin(), b.end(), r1);
sum += int(itr2 - itr1);
}
if (sum < k) {
return true;
}
else {
return false;
}
}
int main() {
cin >> n >> k >> p;
long long a1, b1;
for (int i = 0; i < n; i++) {
cin >> a1;
a.emplace_back(a1);
}
for (int i = 0; i < n; i++) {
cin >> b1;
b.emplace_back(b1);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
long long l = 0, r = p;
while (r - l > 1) {
long long mid = (l + r) / 2;
if (solve(mid)) {
l = mid;
}
else {
r = mid;
}
}
cout << r << endl;
}
seven_three