結果

問題 No.1341 真ん中を入れ替えて門松列
ユーザー leaf_1415leaf_1415
提出日時 2021-01-16 00:33:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,274 ms / 2,000 ms
コード長 1,808 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 95,136 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 19:25:27
合計ジャッジ時間 11,077 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 1,100 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 61 ms
4,376 KB
testcase_10 AC 1,015 ms
4,376 KB
testcase_11 AC 1,274 ms
4,380 KB
testcase_12 AC 906 ms
4,376 KB
testcase_13 AC 963 ms
4,376 KB
testcase_14 AC 1,088 ms
4,376 KB
testcase_15 AC 1,083 ms
4,380 KB
testcase_16 AC 854 ms
4,376 KB
testcase_17 AC 863 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<int, int> P;

ll n, m;
int l[3005], r[3005], a[3005];
vector<P> vec;
priority_queue<P> Q, Q2;
priority_queue<P, vector<P>, greater<P> > Q3;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	rep(i, 1, n){
		cin >> l[i] >> a[i] >> r[i];
		if(l[i] > r[i]) swap(l[i], r[i]);
		vec.push_back(P(l[i], r[i]));
	}
	sort(a+1, a+n+1);
	sort(all(vec));
	reverse(all(vec));
	
	ll ans = -inf;
	rep(i, 0, n){
		
		int cnt = 0;
		while(Q2.size()) Q2.pop();
		while(Q3.size()) Q3.pop();
		
		ll sum = 0, pos = 0;
		for(int j = i; j >= 1; j--){
			while(pos < n && vec[pos].first > a[j]) Q2.push(P(vec[pos].second, vec[pos].first)), pos++;
			if(Q2.size() == 0) goto end;
			sum += Q2.top().first;
			Q2.pop();
		}
		
		while(pos < n) Q3.push(P(vec[pos].second, vec[pos].first)), pos++;
		while(Q2.size()) Q3.push(Q2.top()), Q2.pop();
		
		for(int j = i+1; j <= n; j++){
			while(Q3.size() && Q3.top().first < a[j]) cnt++, Q3.pop();
			if(cnt == 0) goto end;
			sum += a[j];
			cnt--;
		}
		chmax(ans, sum);
		if(ans >= m) break;
		end:;
	}
	
	if(ans < 0) cout << "NO" << endl;
	else{
		cout << "YES" << endl;
		if(ans >= m) cout << "KADOMATSU!" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}
0