結果
問題 |
No.1597 Matrix Sort
|
ユーザー |
|
提出日時 | 2021-07-09 21:51:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 602 bytes |
コンパイル時間 | 2,053 ms |
コンパイル使用メモリ | 197,020 KB |
最終ジャッジ日時 | 2025-01-22 21:31:46 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 WA * 11 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:8:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | int n,k,p; scanf("%d%d%d",&n,&k,&p); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 10 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | rep(j,n) scanf("%d",&b[j]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int n,k,p; scanf("%d%d%d",&n,&k,&p); vector<int> a(n),b(n); rep(i,n) scanf("%d",&a[i]); rep(j,n) scanf("%d",&b[j]); sort(b.begin(),b.end()); auto f=[&](int tar){ int cnt=0; rep(i,n){ cnt+=upper_bound(b.begin(),b.end(),tar-a[i])-b.begin(); cnt+=upper_bound(b.begin(),b.end(),tar+p-a[i])-lower_bound(b.begin(),b.end(),p-a[i]); } return cnt; }; int lo=-1,hi=p; while(hi-lo>1){ int mi=(lo+hi)/2; if(f(mi)>=k) hi=mi; else lo=mi; } printf("%d\n",hi); return 0; }