結果

問題 No.3282 Photos and Friends
ユーザー t98slider
提出日時 2025-09-26 21:49:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,827 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 208,904 KB
実行使用メモリ 12,564 KB
最終ジャッジ日時 2025-09-26 21:49:53
合計ジャッジ時間 9,178 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, p, q;
    cin >> n >> p >> q;
    vector<tuple<ll,ll,ll,int>> a(n);
    vector<pair<ll,ll>> b(n);
    for(int i = 0; i < n; i++){
        auto &&[x, y, z, idx] = a[i];
        idx = i;
        cin >> x >> y >> z;
        for(int j = 0; j < 5; j++){
            if(x - y >= 1){
                ll d = x - y;
                b[i].second += d;
                x -= d;
                z -= d;
                q -= d;
                if(z < 0 || q < 0){
                    cout << "No\n";
                    return 0;
                }
            }
            if(x - z >= 1){
                ll d = x - z;
                b[i].first += d;
                x -= d;
                y -= d;
                p -= d;
                if(y < 0 || p < 0){
                    cout << "No\n";
                    return 0;
                }
            }
        }
    }
    sort(a.begin(), a.end(), [&](tuple<ll,ll,ll,int> lhs, tuple<ll,ll,ll,int> rhs){
        return (get<1>(lhs) + get<2>(lhs)) * get<0>(rhs) < 
                (get<1>(rhs) + get<2>(rhs)) * get<0>(lhs);
    });
    for(auto [x, y, z, idx] : a){
        if(p > q){
            ll d = min({x, y, p});
            p -= d, x -= d;
            b[idx].first += d;
            d = min({x, z, q});
            q -= d, x -= d;
            b[idx].second += d;
        }else{
            ll d = min({x, z, q});
            q -= d, x -= d;
            b[idx].second += d;
            d = min({x, y, p});
            p -= d, x -= d;
            b[idx].first += d;
        }
        if(x != 0){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    for(auto [x, y] : b) cout << x << ' ' << y << '\n';
}
0