Cod sursa(job #1709317)

Utilizator UBB_RANDOMUBB Muntea Zsisku Adam UBB_RANDOM Data 28 mai 2016 11:47:13
Problema Sate2 Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.95 kb
#include <fstream>
#include <algorithm>
#include <string.h>
using namespace std;

ifstream f("sate2.in");
ofstream q("sate2.out");

int pozMin(int st[4], int k){
    int poz = 0, min = st[0];
    for (int i = 1 ; i <k; i++){
        if (min > st[i]){
            min = st[i];
            poz = i;
        }
    }
    return poz;
}

int main()
{
  int st[4], catune[3010], n, t, m, k, poz;
  bool ok;
  f>>t;
  for(;t>0;t--){
    f>>n>>m>>k;
    memset(st,0,4*sizeof(int));
    ok = true;
    for (int i = 0; i < n; i++) f>>catune[i];
    if (m % k != 0) q<<"NU\n";
    else{
        sort(catune,catune+n);

        for (int i = n-1; i> 0; i--){
            poz = pozMin(st,k);
            st[poz] += catune[i];
            if (st[poz] > m / k){
                q<<"NU\n";
                ok = false;
                break;
            }
        }
        if(ok) q<<"DA\n";
    }
  }


  f.close();
  q.close();
  return 0;
}