結果
| 問題 |
No.3282 Photos and Friends
|
| コンテスト | |
| ユーザー |
Iroha_3856
|
| 提出日時 | 2025-09-26 22:14:29 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 133 ms / 2,000 ms |
| コード長 | 2,391 bytes |
| コンパイル時間 | 5,574 ms |
| コンパイル使用メモリ | 335,028 KB |
| 実行使用メモリ | 7,936 KB |
| 最終ジャッジ日時 | 2025-09-26 22:14:41 |
| 合計ジャッジ時間 | 12,294 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = atcoder::modint998244353;
// using mint = double;
#define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++)
#define ll long long
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define siz(x) (int)(x).size()
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll INF = 4e18;
template<class T> using pq = priority_queue<T, vector<T>, less<T>>;
template<class T> using spq = priority_queue<T, vector<T>, greater<T>>;
vector<int> di = {0, 0, 1, -1};
vector<int> dj = {1, -1, 0, 0};
struct Edge {
int to, cost;
};
void solve() {
int N; ll P, Q; cin >> N >> P >> Q;
vector<int> X(N), A(N), B(N);
rep(i, 0, N) cin >> X[i] >> A[i] >> B[i];
vector<int> L(N), R(N);
rep(i, 0, N) {
//0 <= X[i] - A[i] <= B[i]
//A[i] <= X[i] and X[i] - B[i] <= A[i]
L[i] = max(0, X[i] - B[i]), R[i] = min(A[i], X[i]);
if (L[i] <= R[i]) ;
else {
cout << "No" << endl;
break;
}
}
ll Lsum = 0, Rsum = 0;
rep(i, 0, N) {
Lsum += L[i];
Rsum += R[i];
}
ll Xsum = 0;
rep(i, 0, N) Xsum += X[i];
//0 <= a <= P
//0 <= Xsum - a <= Q
//a <= Xsum and Xsum - Q <= a
ll mn = max(0LL, Xsum - Q), mx = min(P, Xsum);
//[mn, mx] に [Lsum, Rsum] が被るか
if (max(mn, Lsum) <= min(mx, Rsum)) {
ll want = max(mn, Lsum);
vector<int> ans(N);
ll now = 0;
rep(i, 0, N) {
ans[i] = L[i];
now += L[i];
}
rep(i, 0, N) {
if (now + R[i] - L[i] <= want) {
ans[i] = R[i];
now += R[i] - L[i];
}
else {
ll p = want - now;
ans[i] += p;
now = want;
}
}
cout << "Yes" << endl;
rep(i, 0, N) cout << ans[i] << " " << X[i] - ans[i] << '\n';
}
else {
cout << "No" << endl;
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int T = 1;
// cin >> T;
while(T--) {
solve();
}
}
Iroha_3856