結果

問題 No.3282 Photos and Friends
ユーザー Rubikun
提出日時 2025-09-26 21:39:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 1,923 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 200,516 KB
実行使用メモリ 10,928 KB
最終ジャッジ日時 2025-09-26 21:40:07
合計ジャッジ時間 8,023 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,P,Q;cin>>N>>P>>Q;
    vector<array<ll,3>> S(N);
    vll ans(N);
    for(int i=0;i<N;i++){
        ll a,b,c;cin>>a>>b>>c;
        if(a>b+c){
            cout<<"No\n";
            return 0;
        }
        ll l=a-c,r=a-b;
        chmax(l,0LL);
        chmax(r,0LL);
        if(b<l||c<r){
            cout<<"No\n";
            return 0;
        }
        ans[i]=mp(l,r);
        a-=l+r;
        b-=l;
        c-=r;
        b=min(b,c);
        S[i]={a,b,c};
        P-=l;
        Q-=r;
    }
    if(P<0||Q<0){
        cout<<"No\n";
        return 0;
    }
    for(int i=0;i<N;i++){
        auto [a,b,c]=S[i];
        if(P>=a){
            ans[i].fi+=a;
            P-=a;
        }else{
            ans[i].fi+=P;
            a-=P;
            P=0;
            ans[i].se+=a;
            Q-=a;
        }
    }
    if(Q<0) cout<<"No\n";
    else{
        cout<<"Yes\n";
        for(auto [a,b]:ans) cout<<a<<" "<<b<<"\n";
    }
}


0