結果
問題 | No.507 ゲーム大会(チーム決め) |
ユーザー |
|
提出日時 | 2017-03-19 21:39:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 25 ms / 3,000 ms |
コード長 | 601 bytes |
コンパイル時間 | 1,339 ms |
コンパイル使用メモリ | 161,804 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-04 23:39:30 |
合計ジャッジ時間 | 2,403 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:6:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6 | scanf("%d%d",&n,&k); | ~~~~~^~~~~~~~~~~~~~ main.cpp:8:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 8 | for(int i=0; i<n; i++) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int n,k; scanf("%d%d",&n,&k); int a[n]; for(int i=0; i<n; i++) scanf("%d",&a[i]); sort(a+1,a+n,greater<int>()); int l=0,r=n; while(l+1!=r) { int m=(l+r)/2; int l2,r2=n-1,c=0; if(r2==m) r2--; for(l2=1; l2<r2; l2++,r2--) { if(l2==m) { r2++; continue; } if(r2==m) r2--; while(l2<r2&&a[l2]+a[r2]<=a[0]+a[m]) { r2--; if(r2==m) r2--; } if(l2>=r2) break; c++; } if(c>=k) r=m; else l=m; } printf("%d\n",l?a[l]:-1); return 0; }