結果

問題 No.1715 Dinner 2
ユーザー cureskol
提出日時 2021-10-22 21:30:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 794 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 176,796 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-23 04:44:03
合計ジャッジ時間 3,895 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n-1);i>=0;i--)
#define ALL(v) v.begin(),v.end()

const int INF=1e9+7;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,d;cin>>n>>d;
  vector<int> p(n),q(n);
  REP(i,n)cin>>p[i]>>q[i];
  int ok=-INF,ng=INF;
  while(ng-ok>1){
    int mid=(ok+ng)>>1;
    int pre=-1,now=0;
    bool out=false;
    REP(_,d){
      int idx=-1;
      REP(i,n){
        if(i==pre)continue;
        if(now-p[i]<mid)continue;
        if(idx==-1||q[i]-p[i]>q[idx]-p[idx])idx=i;
      }
      if(idx==-1){
        out=true;
        break;
      }
      now+=q[idx]-p[idx];
      pre=idx;
    }
    if(out)ng=mid;
    else ok=mid;
  }
  cout<<ok<<endl;
}
0