結果

問題 No.1341 真ん中を入れ替えて門松列
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2020-12-20 15:08:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,095 ms / 2,000 ms
コード長 2,019 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 101,896 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 10:48:19
合計ジャッジ時間 13,375 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 594 ms
4,348 KB
testcase_08 AC 958 ms
4,348 KB
testcase_09 AC 896 ms
4,348 KB
testcase_10 AC 1,095 ms
4,348 KB
testcase_11 AC 1,080 ms
4,348 KB
testcase_12 AC 1,002 ms
4,348 KB
testcase_13 AC 1,046 ms
4,348 KB
testcase_14 AC 1,079 ms
4,348 KB
testcase_15 AC 1,012 ms
4,348 KB
testcase_16 AC 990 ms
4,348 KB
testcase_17 AC 994 ms
4,348 KB
testcase_18 AC 534 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <time.h>
 
using namespace std;

typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)

#define MOD 1000000007

ll n,m;
vector<pair<ll,ll> > vac;
vector<ll> vb;

ll f(ll e){
  ll index = 0;
  ll ret = 0;
  vector<ll> v;
  priority_queue<pair<ll,ll> > pq;
  rep(i,-1,e+1){
    if(i<e){
      while(index<n&&vac[index].fi<=vb[i+1]){
        pq.push(mp(-vac[index].se,vac[index].fi));
        index++;
      }
    }
    else{
      while(index<n){
        pq.push(mp(-vac[index].se,vac[index].fi));
        index++;
      }      
    }
    while(pq.sz>i+1){
      pair<ll,ll> p = pq.top();pq.pop();
      v.pb(-p.fi);
    }
  }
  if(pq.sz<e+1)return -1;
  sort(all(v));
  ll flag = 1;
  rep(i,0,v.sz){
    ret += vb[e+1+i];
    if(v[i]>=vb[e+1+i])flag=0;
  }
  if(flag==0)return -1;
  while(!pq.empty()){
    pair<ll,ll> p = pq.top();pq.pop();
    ret += -p.fi;
  }
  return ret;
}

int main(){
  cin>>n>>m;
  rep(i,0,n){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a>c)swap(a,c);
    vac.pb(mp(a,c));
    vb.pb(b);
  }
  vb.pb(1000000100);
  sort(all(vac));
  sort(all(vb));
  ll mx = -1;
  rep(i,-1,n){
    mx = max(mx,f(i));
  }
  if(mx!=-1){
    cout << "YES" << endl;
    if(mx>=m){
      cout << "KADOMATSU!" << endl;
    }
    else{
      cout << "NO" << endl;
    }
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}
0