1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
#include <iostream> #include <cstdio> #include <cstdio> #include <cstring> #include <vector> #include <cmath> #include <cstdlib> #include <algorithm> #define LMT 5000000 #define ll long long using namespace std; bool cmp(int a,int b) { return a>b; } ll _pow(int a,int p) { ll ans=1; while(p--) { ans=ans*a; if(ans>=LMT) return LMT; } return ans; } int main() { vector<int> vb; int t,n,k; ll total,r; scanf("%d",&t); bool exceed; while(t--) { vb.clear(); total=0; while(scanf("%d",&n)&&n) { vb.push_back(n); } sort(vb.begin(),vb.end(),cmp); exceed=0; for(int i=0;i<vb.size();i++) { r =_pow(vb[i],i+1); r*=2; if(r>LMT) { exceed=1;break; } total+=r; if(total>LMT) { exceed=1;break; } } if(exceed) printf("Too expensive\n"); else printf("%lld\n",total); } return 0; } |