結果
問題 |
No.1597 Matrix Sort
|
ユーザー |
![]() |
提出日時 | 2021-07-09 21:50:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 941 bytes |
コンパイル時間 | 1,717 ms |
コンパイル使用メモリ | 171,668 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-01 15:54:31 |
合計ジャッジ時間 | 10,908 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() using ll=long long; int S(vector<int> &b,int a){//a以上の個数 int L=-1,R=b.size();//Lはa未満 while(R-L>1){ int m=(L+R)>>1; (b[m]<a?L:R)=m; } return b.size()-1-L; } int main(){ ll n,k,p;cin>>n>>k>>p; vector<int> a(n),b(n); REP(i,n)cin>>a[i]; REP(i,n)cin>>b[i]; sort(ALL(a)); sort(ALL(b)); int l=0,r=p;//lはk子未満,rはより少ない while(r-l>1){ int m=(l+r)>>1; ll cnt=0;//m以下の個数を数える REP(i,n){ if(a[i]<=m){//0<=x<=m-a[i]の個数 int A=S(b,0); int B=S(b,m-a[i]+1); cnt+=A-B; cnt+=S(b,p-a[i]); } else{//p-a[i]<=x<=p+m-a[i]の個数 int A=S(b,p-a[i]); int B=S(b,p+m-a[i]+1); cnt+=A-B; } } //cout<<m<<" "<<cnt<<endl; (cnt<k?l:r)=m; } cout<<r<<endl; }