結果

問題 No.1341 真ん中を入れ替えて門松列
ユーザー 👑 kmjpkmjp
提出日時 2021-01-16 00:39:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,552 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 208,652 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 02:18:24
合計ジャッジ時間 2,721 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
ll M;
int B[3030];
pair<int,int> P[3030];
int vis[3030];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) {
		cin>>x>>B[i]>>y;
		if(x>y) swap(x,y);
		if(x==y) return _P("NO\n");
		P[i]={y,x};
	}
	ll ma=-1;
	sort(B,B+N);
	sort(P,P+N);
	
	FOR(k,N+1) {
		ZERO(vis);
		ll ok=0;
		x=N-1;
		for(i=k-1;i>=0;i--) {
			while(x>=0&&B[i]>=P[x].second) x--;
			if(x<0) break;
			vis[x]=1;
			ok+=P[x].first;
			x--;
		}
		if(i>=0) continue;
		x=0;
		for(i=k;i<N;i++) {
			while(x<N&&vis[x]) x++;
			if(x==N||P[x].first>=B[i]) break;
			x++;
			ok+=B[i];
		}
		if(i<N) continue;
		ma=max(ma,ok);
	}
	
	
	if(ma==-1) {
		cout<<"NO"<<endl;
	}
	else {
		cout<<"YES"<<endl;
		if(ma<M) cout<<"NO"<<endl;
		else cout<<"KADOMATSU!"<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0