結果
問題 | No.1597 Matrix Sort |
ユーザー | kumakumaaaaa |
提出日時 | 2021-07-09 22:16:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 343 ms / 1,500 ms |
コード長 | 1,214 bytes |
コンパイル時間 | 1,598 ms |
コンパイル使用メモリ | 172,608 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 16:52:30 |
合計ジャッジ時間 | 7,391 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> // #include <atcoder/modint> #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define INF 2000000000000000000 #define ll long long #define ld long double #define pll pair<ll, ll> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, K, mod; cin >> N >> K >> mod; vector<ll> A(N), B(N); for (ll i = 0; i < N; ++i) { cin >> A.at(i); A.at(i) %= mod; } for (ll i = 0; i < N; ++i) { cin >> B.at(i); B.at(i) %= mod; } sort(rng(A)); sort(rng(B)); ll l = -1, r = mod - 1; while (l + 1 != r) { ll m = (l + r) / 2; ll cnt = 0; for (ll i = 0; i < N; ++i) { ll a = A.at(i); if (a <= m) { ll left = m - a; cnt += upper_bound(rng(B), left) - B.begin(); } ll need = mod - a; ll cap_max = m + mod - a; cnt += upper_bound(rng(B), cap_max) - lower_bound(rng(B), need); } if (cnt >= K) { r = m; } else { l = m; } } cout << r << "\n"; }