結果
| 問題 | No.507 ゲーム大会(チーム決め) | 
| コンテスト | |
| ユーザー |  ikd | 
| 提出日時 | 2017-11-28 23:42:16 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                CE
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 972 bytes | 
| コンパイル時間 | 309 ms | 
| コンパイル使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-11-14 20:17:05 | 
| 合計ジャッジ時間 | 817 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
            
            
            
            
            ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Main.d(35): Error: `cnt < m ? ok : ng` must be surrounded by parentheses when next to operator `=`
ソースコード
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.array, std.range;
  int n, m; rd(n, m);
  auto a=new int[](n);
  foreach(i; 0..n) rd(a[i]);
  auto x=a[0];
  a.popFront;
  sort(a);
  int count(int[] b, int s){
    int cnt=0;
    while(b.length>0){
      auto y=b.back; b.popBack;
      auto p=assumeSorted(b);
      auto ub=p.upperBound(s-y);
      if(ub.length==0) break;
      b=b[($-ub.length+1)..$];
      cnt++; 
    }
    return cnt;
  }
  auto c1=count(a[0..($-1)], x+a.back);
  auto c2=count(a[1..$], x+a.front);
  if(c1>=m){writeln(-1); return;}
  if(c2<m){writeln(a.front); return;}
  int ng=0, ok=n-1;
  while(ok-ng>1){
    auto md=(ok+ng)/2;
    auto cnt=count(a[0..md]~a[(md+1)..$], x+a[md]);
    cnt<m ? ok : ng = md;
  }
  writeln(a[ok]);
}
void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
            
            
            
        