結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー tnakao0123tnakao0123
提出日時 2017-09-22 12:58:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 1,000 ms
コード長 1,747 bytes
コンパイル時間 740 ms
コンパイル使用メモリ 88,068 KB
実行使用メモリ 5,648 KB
最終ジャッジ日時 2023-08-20 09:49:15
合計ジャッジ時間 2,769 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
5,572 KB
testcase_01 AC 47 ms
5,636 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 47 ms
5,628 KB
testcase_13 AC 48 ms
5,428 KB
testcase_14 AC 46 ms
5,436 KB
testcase_15 AC 47 ms
5,648 KB
testcase_16 AC 45 ms
5,380 KB
testcase_17 AC 44 ms
5,452 KB
testcase_18 AC 45 ms
5,316 KB
testcase_19 AC 47 ms
5,440 KB
testcase_20 AC 45 ms
5,464 KB
testcase_21 AC 46 ms
5,276 KB
testcase_22 AC 47 ms
5,548 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 568.cc: No.568 じゃんじゃん 落とす 委員会 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_A = 100000;
const int MAX_B = 100000;
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

int xs[MAX_N];
pii aps[MAX_N], bps[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) {
    int xi, ai, bi;
    scanf("%d%d%d", &xi, &ai, &bi);
    xs[i] = xi;
    aps[i] = pii(ai, i);
    bps[i] = pii(bi, i);
  }

  sort(aps, aps + n);
  sort(bps, bps + n);

  int n2 = 0, n3 = 0;
  for (int i = 0; i < n; i++) {
    xs[i]++;
    if (xs[i] >= 2) {
      n2++;
      if (xs[i] >= 3) n3++;
    }
  }
  //printf("n2=%d, n3=%d\n", n2, n3);

  int sa = 0, sb = MAX_B + 1;
  int minn3 = INF;

  for (int ai = 0, bi = n;;) {
    //printf("ai=%d, bi=%d\n", ai, bi);
    while (bi > 0 && n2 < m) {
      sb--;
      while (bi > 0 && bps[bi - 1].first >= sb) {
	bi--;
	int &k = bps[bi].second;
	xs[k]++;
	if (xs[k] == 3) n3++;
	else if (xs[k] == 2) n2++;
      }
    }

    if (n2 >= m && minn3 > n3) minn3 = n3;
    if (ai >= n) break;

    while (ai < n && aps[ai].first <= sa) {
      int &k = aps[ai].second;
      if (xs[k] == 3) n3--;
      else if (xs[k] == 2) n2--;
      xs[k]--;
      ai++;
    }
    sa++;
  }

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