Cod sursa(job #1709334)

Utilizator UBB_RANDOMUBB Muntea Zsisku Adam UBB_RANDOM Data 28 mai 2016 11:51:12
Problema Sate2 Scor 0
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.92 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];
    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){
            ok = false;
            break;
        }
    }
    for (int i = 0; i<k; i++) if (st[i] != m/k) ok = false;
    if(ok) q<<"DA\n";
    else q<<"NU\n";
  }


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