This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
int main()
{
int n, i, t, j, a, b, c, k, l;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d", &n);
for(i=1;i<=n;i++){
scanf("%d", &t);
a = b = c = 0;
for(j=t/8;j>=0;j--){
for(k=(t-(j*8))/5;k>=0;k--){
if(j+k+((t-(j*8)-(k*5))/3)>a+b+c && (a!=0 || b!=0 || c!=0)) break;
if((t-(j*8)-(k*5))%3==0){
if(j+k+((t-(j*8)-(k*5))/3)<a+b+c || (a==0 && b==0 && c==0)){
a = j;
b = k;
c = (t-(j*8)-(k*5))/3;
}
else if(j+k+((t-(j*8)-(k*5))/3)==a+b+c){
if(a<j){
a = j;
b = k;
c = (t-(j*8)-(k*5))/3;
}
else if(a==j){
if(b<k){
a = j;
b = k;
c = (t-(j*8)-(k*5))/3;
}
}
}
}
}
}
if(a==0 && b==0 && c==0) printf("-1\n");
else{
for(j=1;j<=c;j++) printf("3");
for(j=1;j<=b;j++) printf("5");
for(j=1;j<=a;j++) printf("8");
printf("\n");
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |