結果

問題 No.1715 Dinner 2
ユーザー tnakao0123tnakao0123
提出日時 2021-10-23 19:56:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,685 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 48,192 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 03:22:52
合計ジャッジ時間 1,632 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1715.cc:  No.1715 Dinner 2 - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_D = 1000;
const int MAX_P = 100000;
const int MAX_PD = MAX_P * MAX_D;
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

pii pqs[MAX_N];
int ts[MAX_P + 1][2];

/* subroutines */

bool check(int d, int maxp, int x) {
  int s = 0, ci = -1;
  while (d--) {
    int p = min(maxp, x - s);
    if (ts[p][0] != -1 && ts[p][0] != ci) {
      ci = ts[p][0];
      s -= pqs[ci].second;
    }
    else if (ts[p][1] != -1 && ts[p][1] != ci) {
      ci = ts[p][1];
      s -= pqs[ci].second;
    }
    else
      return false;

    if (s > x) return false;
  }
  return true;
}

/* main */

int main() {
  int n, d;
  scanf("%d%d", &n, &d);

  int maxp = 0;
  for (int i = 0; i < n; i++) {
    int pi, qi;
    scanf("%d%d", &pi, &qi);
    pqs[i] = pii(pi, -pi + qi);
    maxp = max(maxp, pi);
  }
  sort(pqs, pqs + n);

  memset(ts, -1, sizeof(ts));

  int mxq0 = -INF, mxq1 = -INF, mxi0 = -1, mxi1 = -1;
  for (int p = 1, i = 0; p <= maxp; p++) {
    while (i < n && pqs[i].first <= p) {
      if (mxq0 < pqs[i].second)
	mxq1 = mxq0, mxi1 = mxi0, mxq0 = pqs[i].second, mxi0 = i;
      else if (mxq1 < pqs[i].second)
	mxq1 = pqs[i].second, mxi1 = i;
      i++;
    }

    ts[p][0] = mxi0, ts[p][1] = mxi1;
    //printf("%d,%d ", ts[p][0], ts[p][1]);
  }
  //putchar('\n');

  int x0 = 0, x1 = maxp * d;
  while (x0 + 1 < x1) {
    int x = (x0 + x1) / 2;
    if (check(d, maxp, x)) x1 = x;
    else x0 = x;
  }

  printf("%d\n", -x1);
  return 0;
}
0