結果
問題 | No.507 ゲーム大会(チーム決め) |
ユーザー | dohatsutsu |
提出日時 | 2017-04-21 23:11:57 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 763 bytes |
コンパイル時間 | 1,520 ms |
コンパイル使用メモリ | 146,920 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-27 20:42:55 |
合計ジャッジ時間 | 3,068 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | WA | - |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | WA | - |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 52 ms
4,380 KB |
testcase_08 | AC | 48 ms
4,376 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 2 ms
4,376 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; int N,M,K; int a[100000]; bool check(int x){ int sum=K+x; int cnt=0; int h=0; int index=lower_bound(a,a+N,x)-a; if(h==index)h++; for(int i=N-1;i>=0;i--){ if(i==index)continue; while(h<N && a[i]+a[h]<=sum){ h++; if(h==index)h++; } if(h<i&&sum<a[i]+a[h]){ cnt++; // cout<<i<<' '<<h<<endl; h++; } } return ( cnt<M ); } int main(){ cin>>N>>M>>K; N--; for(int i=0;i<N;i++){ cin>>a[i]; } sort(a,a+N); int left=0,right=N-1,mid; while(left<right){ mid=(left+right)/2; if(check(mid))right=mid; else left=mid+1; } if( check(N-1) ==false ) cout<<-1<<endl; else cout<<a[left]<<endl; return 0; }