QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1081#686251#9422. Two-star ContestxydCatGirlxydCatGirlFailed.2024-10-29 09:41:052024-10-29 09:41:06

Details

Extra Test:

Invalid Input

input:

1 1 1

output:


result:

FAIL Expected EOLN (stdin, line 1)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#686251#9422. Two-star ContestxydCatGirl#AC ✓77ms25520kbC++201.8kb2024-10-29 09:39:442024-10-29 09:39:45

answer

#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define ar(i) array<int, i>
using namespace std;
const int N=4e5+5, mod=1e9+7;
int n,m,k;
int genshin;
vector<int>p[N];
int l[N],r[N];
int s[N];
int id[N];
int ans[N];
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin>>genshin;
    while(genshin--){
        cin>>n>>m>>k;
        for(int i=1;i<=n;++i){
            id[i]=i;
            cin>>s[i];
            p[i].resize(m+1);
            int sum=0,cnt=0;
            for(int j=1;j<=m;++j){
                cin>>p[i][j];
                if(p[i][j]==-1)++cnt;
                else sum+=p[i][j];
            }
            l[i]=sum;
            r[i]=sum+cnt*k;
        }
        sort(id+1,id+1+n,[&](int x,int y){
            return s[x]<s[y];
        });
        int mx=-1,upd=0;
        bool flag=1;
        for(int i=1;i<=n;++i){
            int li=l[id[i]],ri=r[id[i]];
            if(mx+1>ri){
                flag=0;
                break;
            }
            ans[id[i]]=max(mx+1ll,li);
            upd=max(upd,ans[id[i]]);
            ans[id[i]]-=li;
            if(s[id[i]]!=s[id[i+1]])mx=max(mx,upd);
        }
        if(!flag)
            cout<<"No"<<endl;
        else{
            cout<<"Yes"<<endl;
            for(int i=1;i<=n;++i){
                for(int j=1;j<=m;++j){
                    if(p[i][j]!=-1)
                        cout<<p[i][j]<<" ";
                    else{
                        if(ans[i]<=k)cout<<ans[i]<<" ";
                        else cout<<k<<" ";
                        ans[i]-=min(k,ans[i]);
                    }
                }
                cout<<endl;
            }
        }
    }
    // cerr<<fixed<<setprecision(2)<<(double)clock()/CLOCKS_PER_SEC<<endl;
    return 0;
}