Cod sursa(job #641657)

Utilizator Smaug-Andrei C. Smaug- Data 29 noiembrie 2011 00:14:23
Problema Grupuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
//----------------------------------------------------
// Discard the "colums" that are occupied by only one
// type of animal. The sum of the remaining animals
// divided by the size of the groups gives the answer.
//----------------------------------------------------

#include <cstdio>

#define MAXN 100010

int main(){

  freopen("grupuri.in", "r", stdin);
  freopen("grupuri.out", "w", stdout);

  int K, N, i;
  static int A[MAXN];
  long long sum = 0;

  scanf("%d%d", &K, &N);
  for(i=0; i<N; i++){
    scanf("%d", A+i);
    sum+=A[i];
  }

  for(i=N-1; sum/K < A[i]; i--){
    sum-=A[i]; K--;
  }
    
  printf("%lld", sum/K);

}