結果

問題 No.3282 Photos and Friends
ユーザー Carpenters-Cat
提出日時 2025-09-26 22:04:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 618 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 197,952 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2025-09-26 22:05:03
合計ジャッジ時間 10,905 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
	int N;
	cin >> N;
	ll P, Q;
	cin >> P >> Q;
	std::vector<ll> L(N), R(N), X(N);
	for (int i = 0; i < N; i ++) {
		ll a, b, x;
		cin >> x >> a >> b;
		X[i] = x;
		if (a + b < x) {
			puts("No");
			return 0;
		}
		L[i] = max(0ll, x - b);
		R[i] = min(a, x);
	}
	ll sx = accumulate(X.begin(), X.end(), 0ll);
	if (P + Q < sx) {
		puts("No");
		return 0;
	}
	ll Pl = max(0ll, sx - Q);
	ll sl = accumulate(L.begin(), L.end(), 0ll), sr = accumulate(R.begin(), R.end(), 0ll);
	if (sr < Pl || P < sl) {
		puts("No");
		return 0;
	}
	puts("Yes");
	P -= sl;
	for (int i = 0; i < N; i ++) {
		ll a = L[i];
		ll d = min(P, R[i] - L[i]);
		cout << a + d << " " << (X[i] - a - d) << endl;
		P -= d;
	}
}
0