結果

問題 No.1341 真ん中を入れ替えて門松列
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2019-12-15 22:32:45
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,803 bytes
コンパイル時間 1,455 ms
コンパイル使用メモリ 99,548 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 10:51:32
合計ジャッジ時間 3,806 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 131 ms
4,348 KB
testcase_08 AC 83 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 192 ms
4,348 KB
testcase_15 AC 172 ms
4,348 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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 <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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 print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll f(vector<ll> &v, vector<pair<ll,ll> > &vp, ll p){
  ll sum = 0;
  ll flag = 1;
  vector<pair<ll,ll> > vp2;
  ll index = 0;
  rep(i,0,vp.sz){
    if(index>=p){
      rep(j,i,vp.sz){
        vp2.pb(mp(vp[i].se,vp[i].fi));
      }
      break;
    }
    if(v[index]<vp[i].fi){
      sum += vp[i].se;
      index++;
    }
    else{
      vp2.pb(mp(vp[i].se,vp[i].fi));
    }
  }
  if(index!=p)return -1;
  sort(all(vp2));
  rep(i,0,vp2.sz){
    if(v[index]>vp2[i].fi){
      sum += v[index];
      index++;
    }
    else{
      return -1;
    }
  }
  return sum;
}

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