Cod sursa(job #2242208)

Utilizator Robert_VRVRobert Vadastreanu Robert_VRV Data 18 septembrie 2018 08:51:52
Problema Shop Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <stdio.h>
#include <math.h>
#include <algorithm>

int answer[1 + 30];

struct Money {
  long long val;
  int freq, ind;
  bool operator <(const Money& other) const {
    return this->val > other.val;
  }
};

int main() {

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

  int n, c;
  long long l;
  scanf("%d%d%lld", &n, &c, &l);
  Money money[1 + 30];
  for (int i = 1; i <= n; i++) {
    long long a;
    scanf("%lld%d", &a, &money[i].freq);
    a = (long long)pow(c, a);
    money[i].val = a;
    money[i].ind = i;
  }
  std::sort(money + 1, money + n + 1);
  int answerCount = 0;
  for (int i = 1; i <= n; i++) {
    answer[money[i].ind] = (int)std::min((long long)money[i].freq, l / money[i].val);
    answerCount += answer[money[i].ind];
	  l -= answer[money[i].ind] * money[i].val;
  }
  printf("%d\n", answerCount);
  for (int i = 1; i <= n; i++)
    printf("%d ", answer[i]);
  printf("\n");

  fclose(stdin);
  fclose(stdout);

	return 0;
}