/home/toolbox/public_html/solutions/118/11824/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdlib.h>
7 #include <math.h>
8 #include <stdint.h>
9 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 /* fprintf(stderr, "functionName: message", varslist); */
17
18 /*
19 * Author: Isaac Traxler
20 * Date: 2021-12-5
21 * Purpose: fun
22 * Problem: 11824 - A Minimum Land Price
23 */
24
25 /*
26 * This template reads data a specified number of times.
27 */
28
29 #define MAX_PRICES 50
30 #define BUDGET 5000000
31
32 int numberOfTimes;
33 int prices[MAX_PRICES];
34 int priceCnt;
35
36 void init()
37 {
38 /* FUNCTION init */
39 scanf("%d ", &numberOfTimes);
40 } /* FUNCTION init */
41
42 void dump()
43 {
44 /* FUNCTION dump */
45 } /* FUNCTION dump */
46
47 int compare(const void *a, const void *b)
48 {
49 /* FUNCTION compare */
50 return ( *(int*)b - *(int*)a );
51 } /* FUNCTION compare */
52
53 void getInput()
54 {
55 /* FUNCTION getInput */
56 priceCnt = 0;
57 scanf(" %d ", &prices[priceCnt]);
58 while (0 != prices[priceCnt])
59 {
60 /* while */
61 DEBUG printf("prices[%d] = %d\n", priceCnt, prices[priceCnt]);
62 priceCnt++;
63 scanf(" %d ", &prices[priceCnt]);
64 } /* while */
65 qsort(prices, priceCnt, sizeof(int), compare);
66 } /* FUNCTION getInput */
67
68 void process()
69 {
70 /* FUNCTION process */
71 int tot;
72 int i;
73 int j;
74 int tmp;
75
76 tot = 0;
77 for (i=0; (BUDGET > tot) && (priceCnt > i); i++)
78 {
79 /* for each price */
80 tmp = 2 * prices[i];
81 for (j=0; j<i; j++)
82 {
83 /* do multiplications */
84 tmp = tmp * prices[i];
85 } /* do multiplications */
86 tot = tot + tmp;
87 DEBUG printf("prices[%d] = %d (tmp %d) (tot %d)\n", i, prices[i], tmp, tot);
88 } /* for each price */
89 if (BUDGET < tot)
90 {
91 printf("Too expensive\n");
92 }
93 else
94 {
95 printf("%d\n", tot);
96 }
97 } /* FUNCTION process */
98
99 int main()
100 {
101 /* main */
102 int i;
103
104 init();
105 for (i=0; i<numberOfTimes; i++)
106 {
107 /* while */
108 getInput();
109 process();
110 } /* while */
111
112 return EXIT_SUCCESS;
113 } /* main */
114
115