結果

問題 No.1341 真ん中を入れ替えて門松列
ユーザー 沙耶花沙耶花
提出日時 2021-01-15 23:06:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 822 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 208,032 KB
最終ジャッジ日時 2025-01-17 20:24:44
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |                 scanf("%lld %lld %lld",&a,&b,&c);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000



int main(){
	
	int N;
	cin>>N;
	long long M;
	cin>>M;
	
	vector<long long> B(N);
	vector<pair<long long,long long>> CA(N);
	rep(i,N){
		long long a,b,c;
		scanf("%lld %lld %lld",&a,&b,&c);
		B[i] = b;
		if(a>c)swap(c,a);
		CA[i] = make_pair(c,a);
	}
	sort(B.begin(),B.end());
	sort(CA.begin(),CA.end());
	long long ans= -1;
	
	rep(i,N+1){
		multiset<long long> S;
		long long cur = 0LL;
		rep(j,N){
			if(j<i){
				S.insert(B[j]);
			}
			else{
				cur += B[j];
			}
		}
		vector<long long> t;
		for(int j=N-1;j>=0;j--){
			auto it = S.lower_bound(CA[j].second);
			if(it==S.begin()){
				t.push_back(CA[j].first);
			}
			else{
				it--;
				cur += CA[j].first;
				S.erase(it);
			}
		}
		reverse(t.begin(),t.end());
		if(S.size()==0){
			bool f = true;
			for(int j=0;j<t.size();j++){
				if(B[i+j]>t[j])continue;
				f=false;
				break;
			}
			if(f)ans = max(ans,cur);
		}
	}

	if(ans==-1){
		cout<<"NO"<<endl;
	}
	else{
		cout<<"YES"<<endl;
		if(M<=ans)cout<<"KADOMATSU!"<<endl;
		else cout<<"NO"<<endl;
	}
	
    return 0;
}
0