結果

問題 No.1715 Dinner 2
ユーザー milanis48663220
提出日時 2021-10-22 22:02:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 2,504 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 118,028 KB
最終ジャッジ日時 2025-01-25 03:39:25
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
return vector<vector<T>>(n, vector<T>(m, v));
}
template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}
template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
if(v.empty()) {
cout << endl;
return;
}
for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
cout << v.back() << endl;
}
using P = pair<int, int>;
const int INF = 1e9;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int n, d; cin >> n >> d;
vector<int> p(n), q(n);
for(int i = 0; i < n; i++) cin >> p[i] >> q[i];
auto judge = [&](int lb) -> bool{
// debug_value(lb);
auto dp = vec2d(d, n, -INF);
for(int i = 0; i < n; i++) {
if(-p[i] >= lb) dp[0][i] = q[i]-p[i];
}
for(int i = 1; i < d; i++){
int mx1 = -INF, mx2 = -INF;
for(int j = 0; j < n; j++){
if(dp[i-1][j] > mx1){
mx2 = mx1;
mx1 = dp[i-1][j];
}else if(dp[i-1][j] > mx2){
mx2 = dp[i-1][j];
}
}
for(int j = 0; j < n; j++){
if(dp[i-1][j] == mx1){
if(mx2-p[j] >= lb) dp[i][j] = mx2-p[j]+q[j];
}else{
if(mx1-p[j] >= lb) dp[i][j] = mx1-p[j]+q[j];
}
}
}
for(int j = 0; j < n; j++){
if(dp[d-1][j] != -INF) return true;
}
return false;
};
int l = 0, r = 1e9;
while(r-l > 1){
int x = (l+r)/2;
if(judge(-x)) r = x;
else l = x;
}
cout << -r << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0