http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=2924&mosmsg=Submission+received+with+ID+14034373
#include<iostream>
#include <cstdio>
#include <algorithm>
#include<cmath>
#define max 5000000
using namespace std;
int main ()
{
long long test,ary[128],i,sum,j,p,t,ar[128];
cin>>test;
while(test--)
{
t=0;
for(i=0;; i++)
{
cin>>ar[i];
if(ar[i]==0)
{
break;
}
else
{
ary[t++]=ar[i] ;
}
}
sort(ary,ary+t);
sum=0;
int s;
p=1;
for(j=t-1,p=1; j>=0; j--,p++)
{
s=1;
for(int x=0;x<p;x++)
{
s=s*ary[j];
}
sum+=(2*s) ;
if(sum>max) break;
}
if(sum<=max)
{
cout<<sum<<endl;
}
else
{
cout<<"Too expensive"<<endl;
}
}
return 0;
}
#include<iostream>
#include <cstdio>
#include <algorithm>
#include<cmath>
#define max 5000000
using namespace std;
int main ()
{
long long test,ary[128],i,sum,j,p,t,ar[128];
cin>>test;
while(test--)
{
t=0;
for(i=0;; i++)
{
cin>>ar[i];
if(ar[i]==0)
{
break;
}
else
{
ary[t++]=ar[i] ;
}
}
sort(ary,ary+t);
sum=0;
int s;
p=1;
for(j=t-1,p=1; j>=0; j--,p++)
{
s=1;
for(int x=0;x<p;x++)
{
s=s*ary[j];
}
sum+=(2*s) ;
if(sum>max) break;
}
if(sum<=max)
{
cout<<sum<<endl;
}
else
{
cout<<"Too expensive"<<endl;
}
}
return 0;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন