結果
| 問題 | 
                            No.1597 Matrix Sort
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-07-09 22:12:31 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 163 ms / 1,500 ms | 
| コード長 | 1,190 bytes | 
| コンパイル時間 | 984 ms | 
| コンパイル使用メモリ | 112,780 KB | 
| 実行使用メモリ | 160,296 KB | 
| 最終ジャッジ日時 | 2024-07-01 16:44:13 | 
| 合計ジャッジ時間 | 4,467 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
using namespace std;
constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;
//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K >> M;
	vector<long long>a(N);
	vector<long long>b(2 * M);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> L;
		b[L]++;
		b[L + M]++;
	}
	for (int i = 1; i < 2 * M; i++) {
		b[i] += b[i - 1];
	}
	L = -1, R = M - 1;
	while (R - L > 1) {
		int mid = (L + R) / 2;
		long long num = 0;
		for (int i = 0; i < N; i++) {
			num += b[M + mid - a[i]] - b[M - a[i] - 1];
		}
		if (num < K)L = mid;
		else R = mid;
	}
	cout << R << endl;
}