結果

問題 No.3282 Photos and Friends
ユーザー Tatsu_mr
提出日時 2025-09-28 15:12:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,707 bytes
コンパイル時間 2,839 ms
コンパイル使用メモリ 279,284 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2025-09-28 15:12:16
合計ジャッジ時間 9,322 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) For(i, 0, n)
#define rFor(i, a, b) for(int i = (a); i >= (b); i--)
#define ALL(v) (v).begin(), (v).end()
#define rALL(v) (v).rbegin(), (v).rend()
#define SZ(v) ((int)(v).size())

using lint = long long;
using ld = long double;

const int INF = 2000000000;
const lint LINF = 1000000000000000000;
// 真上から反時計回り
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int di8[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dj8[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct SetupIo {
    SetupIo() {
        ios::sync_with_stdio(false); cin.tie(nullptr);
        cout << fixed << setprecision(15);
        cerr << fixed << setprecision(15);
    }
} setupio;

template <class T>
bool chmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
bool chmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0; 
}
template <class T>
T mypow(T a, T b) {
    T res = 1;
    while (b) {
        if (b & 1) { res *= a; }
        a *= a; b >>= 1;
    }
    return res;
}
template <class T>
T modpow(T a, T b, T mod) {
    T res = 1;
    while (b) {
        if (b & 1) { res = (res * a) % mod; }
        a = (a * a) % mod; b >>= 1;
    }
    return res;
}

int main() {
    lint N, P, Q;
    cin >> N >> P >> Q;
    vector<lint> X(N), A(N), B(N);
    rep(i, N) {
        cin >> X[i] >> A[i] >> B[i];
    }

    // 自明な No その 1
    rep(i, N) {
        if (A[i] + B[i] < X[i]) {
            cout << "No\n";
            return 0;
        }
    }

    // 自明な No その 2
    if (accumulate(ALL(X), 0LL) > P + Q) {
        cout << "No\n";
        return 0;
    }
    
    // X[i] - B[i] <= a[i] <= A[i]
    // sum_X - Q <= sum_a <= P
    vector<lint> a(N);

    // 一旦最低限割り当てる
    rep(i, N) {
        a[i] = X[i] - B[i];
    }

    lint sum_a = accumulate(ALL(a), 0LL);

    // 2 つの条件を満たしながら a[i] を増やしていく
    rep(i, N) {
        lint add = min(A[i] - a[i], P - sum_a);
        a[i] += add;
        sum_a += add;
    }
    
    vector<lint> b(N);
    rep(i, N) {
        b[i] = X[i] - a[i];
    }

    bool ok = true;
    rep(i, N) {
        if (!(0 <= a[i] && a[i] <= A[i])) {
            ok = false;
        }
        if (!(0 <= b[i] && b[i] <= B[i])) {
            ok = false;
        }
    }
    if (!(accumulate(ALL(a), 0LL) <= P)) {
        ok = false;
    }
    if (!(accumulate(ALL(b), 0LL) <= Q)) {
        ok = false;
    }

    if (ok) {
        cout << "Yes\n";
        rep(i, N) {
            cout << a[i] << " " << b[i] << "\n";
        }
    } else {
        cout << "No\n";
    }
}
0