結果

問題 No.1597 Matrix Sort
ユーザー fura
提出日時 2021-07-09 22:44:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 661 ms / 1,500 ms
コード長 634 bytes
コンパイル時間 2,579 ms
コンパイル使用メモリ 198,520 KB
最終ジャッジ日時 2025-01-22 22:22:40
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         lint k; scanf("%d%lld%d",&n,&k,&p);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         rep(i,n) scanf("%d",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~
main.cpp:13:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         rep(j,n) scanf("%d",&b[j]);
      |                  ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n,p;
	lint k; scanf("%d%lld%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){
		lint 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;
}
0