結果
| 問題 | No.1715 Dinner 2 | 
| コンテスト | |
| ユーザー |  inksamurai | 
| 提出日時 | 2021-10-22 22:57:49 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,491 bytes | 
| コンパイル時間 | 1,763 ms | 
| コンパイル使用メモリ | 176,640 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-23 06:50:06 | 
| 合計ジャッジ時間 | 17,692 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 36 WA * 2 | 
ソースコード
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define sz(a) (ll)a.size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define drep(i,n) for(ll i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3aILRlt ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
using pii=pair<ll,ll>;
using tpii=pair<pii,ll>;
using vi=vector<ll>;
int main(){
_3aILRlt;
	ll n,d;
	cin>>n>>d;
	vec(pii) a(n);
	rep(i,n){
		cin>>a[i].fi>>a[i].se;
	}
	sort(all(a),[](pii l,pii r){
		return -l.fi+l.se>-r.fi+r.se;
	});
	auto f=[&](ll x)->bool{
		
		
		vec(ll) cand={-1};
		rep(i,min(n,100ll)){
			cand.pb(i);
		}
		for(auto oid : cand){
			bool gokita=1;
			ll now=0;
			rep(_d,d){
				ll maxima=-1e15,id=-1;
				rep(i,n){
					if(i==oid) continue;
					if(now-a[i].fi>=x){
						if(-a[i].fi+a[i].se>maxima){
							maxima=-a[i].fi+a[i].se;
							id=i;
						}
					}
				}
				if(id==-1){
					gokita=0;
				}
				now+=maxima;
				oid=id;
			}
			if(gokita) return true;
		}
		return false;
	};
	ll l=-1e15-1,r=1e15+1,c=l;
	while(l<=r){
		ll m=(l+r)/2;
		if(f(m)){
			c=m;
			l=m+1;
		}else{
			r=m-1;
		}
	}
	rep(i,n){
		rep(j,n){
			if(i==j) continue;
			ll now=0,er=1e15;
			rep(_d,d){
				if(_d%2==0){
					now-=a[i].fi;
					er=min(er,now);
					now+=a[i].se;
				}else{
					now-=a[j].fi;
					er=min(er,now);
					now+=a[j].se;
				}
			}
			c=max(c,er);
		}
	}
	cout<<c<<"\n";
//	
	return 0;
}
            
            
            
        