結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー ikdikd
提出日時 2017-11-28 23:42:16
言語 D
(dmd 2.106.1)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 972 bytes
コンパイル時間 30 ms
コンパイル使用メモリ 6,688 KB
最終ジャッジ日時 2024-04-27 02:30:24
合計ジャッジ時間 519 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.d(35): Error: `cnt < m ? ok : ng` must be surrounded by parentheses when next to operator `=`

ソースコード

diff #

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));
  }
}
0