結果

問題 No.1715 Dinner 2
ユーザー auauaauaua
提出日時 2021-10-22 22:38:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,992 bytes
コンパイル時間 1,924 ms
コンパイル使用メモリ 183,192 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 13:58:57
合計ジャッジ時間 2,898 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 5 ms
4,348 KB
testcase_31 AC 5 ms
4,348 KB
testcase_32 AC 7 ms
4,348 KB
testcase_33 AC 7 ms
4,348 KB
testcase_34 AC 8 ms
4,348 KB
testcase_35 AC 8 ms
4,348 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=200010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;

//SegmentTree
template< typename Monoid >
struct SegmentTree
{
  using F = function< Monoid(Monoid, Monoid) >;
 
  int sz;
  vector< Monoid > seg;
 
  const F f;
  const Monoid M1;
 
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
 
  void set(int k, const Monoid &x)
  {
    seg[k + sz] = x;
  }
 
  void build()
  {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  void update(int k, const Monoid &x)
  {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  Monoid query(int a, int b)
  {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
 
  Monoid operator[](const int &k) const
  {
    return seg[k + sz];
  }
};
 
void solve(){
    ll n,d;cin>>n>>d;
    vector<pll>x(0);
    rep(i,n){
        ll a,b;cin>>a>>b;
        x.pb(mp(-a,b-a));
    }
    sort(all(x));

    SegmentTree<pair<pll,pll> >seg(n,[](pair<pll,pll> a,pair<pll,pll> b){
        pair<pll,pll>c;
        if(a.fi.fi>b.fi.fi){
            c=a;
            if(a.se.fi<b.fi.fi)c.se=b.fi;
        }else{
            c=b;
            if(b.se.fi<a.fi.fi)c.se=a.fi;
        }
        return c;
    },mp(mp(-inf,-1),mp(-inf,-1)));
    rep(i,n){
        seg.update(i,mp(mp(x[i].se,i),mp(-inf,-1)));
    }
    ll l=0,r=inf;
    while(r-l>1){
        ll mid=(r+l)/2;
        ll la=-1;
        ll now=0;
        bool f=1;
        rep(i,d){
            ll p=lower_bound(all(x),mp(-now-mid,-inf))-x.begin();
            pair<pll,pll>c=seg.query(p,n);
            if(c.fi.se==-1){
                f=0;
                break;
            }
            if(c.fi.se!=la){
                la=c.fi.se;
                now+=c.fi.fi;
            }else{
                if(c.se.se==-1){
                    f=0;
                    break;
                }
                la=c.se.se;
                now+=c.se.fi;
            }
        }
        if(f)r=mid;
        else l=mid;
    }
    cout<<-r<<endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0