#include <stdio.h> #include <algorithm> #include <functional> using namespace std; #define MONEY_LIMIT 2500000 int pow(int base, int exponent) { int power = 1; for (int i = 1; i <= exponent; i++) { power *= base; if (power > MONEY_LIMIT) return power; } return power; } int main() { int cases; scanf("%d", &cases); for (; cases; cases--) { int a[40], n = -1; do { n++; scanf("%d", &a[n]); } while (a[n] != 0); sort(a, a + n, greater<int>()); int total_price = 0; for (int i = 0; i < n; i++) { total_price += pow(a[i], i + 1); if (total_price > MONEY_LIMIT) break; } if (total_price > MONEY_LIMIT) printf("Too expensive\n"); else printf("%d\n", total_price << 1); } return 0; }
Thursday, April 23, 2015
UVa 11824 - A Minimum Land Price
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment