General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
114893372 Contestant:
satvikb
1515C - 17 C++17 (GCC 7-32) Accepted 78 ms 3924 KB 2021-05-02 18:02:59 2021-05-02 21:19:41
→ Source
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
using pi = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vector<int> >;
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()

//const int inf = 9e18;
const int NUM=1000030;
const int N = 10000000;
vector<int> lp, sieve;
vector<int> pr;
void primefactor();
int binpow(int a, int b);
int binpow(int a, int b, int mod);
int gcd(int a, int b);
int lcm (int a, int b);
bool comp(int a, int b);
int inversemod(int a, int mod);
void calc_sieve();

void test()
{
    int n,m,x,i;
    cin>>n>>m>>x;
    vi temp(n);
    vector<pi> arr(n);
    for(i=0;i<n;i++) 
    {
        cin>>arr[i].ff;;
        arr[i].ss=i;
        temp[i]=arr[i].ff;
    }

    sort(all(arr));

    vi ans(n);

    int flag=1;
    int assign=m;
    for(i=n-1;i>=0;i--) 
    {
        if(flag)
        {
            ans[arr[i].ss]=assign;
            assign--;
            if(assign==0)
            {
                flag=0;
                assign=1;
            }
        }
        else 
        {
            ans[arr[i].ss]=assign;
            assign++;
            if(assign==m+1)
            {
                flag=1;
                assign=m;
            }
        }
    }
    vi sum(m, 0);

    for(i=0;i<n;i++) 
    {
        sum[ans[i]-1]+=temp[i];
    }
    sort(all(sum));

    if(sum[m-1]-sum[0]<=x)
    {
        cout<<"YES"<<endl;
        for(i=0;i<n;i++) cout<<ans[i]<<" ";
        cout<<endl;
    }
    else cout<<"NO"<<endl;


}

signed main()
{
//    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--) test();
    return 0;
}

//    1. Take care of the corner cases, write one or two tests that seem to be the cases.
//    2. Check the bounds on the intput and decide the algorithm.
//    3. Make the test cases for the bounds, try to include 0, 1, 2 cases in the new test cases, and if possible, scale the cases.
//    4. Check for overflow and the array bounds carefully, always take care of the decreasing loop.

void calc_sieve() //credits: Anish_Sofat
{
    sieve.resize(NUM+1,0);
    for (int x = 2; x <= NUM; x++)
        {
            if (sieve[x]) continue;
            for (int u = x; u <= NUM; u += x)
            {
                    sieve[u] = x ;
            }
        }
}

void primefactor()
{
    lp.resize(N+1,0);
    for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}

int binpow(int a, int b)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int binpow(int a, int b, int mod)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}

int gcd(int a, int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}

int lcm (int a, int b)
{
    return ((a / gcd(a, b)) * b);
}

bool comp(int a, int b)
{
    return a>b;
}

int inversemod(int a, int mod)
{
    return binpow(a,mod-2, mod);
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details