Guest User

Untitled

a guest
Jul 3rd, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Main {
  5. public static void main(String args[]) throws IOException {
  6.  
  7. //write your code here
  8. BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
  9. int n=Integer.parseInt(bu.readLine());
  10. int i,j,m[]={4,7},c[]=new int[n+1],fs[][]=new int[n+1][2];
  11. for(i=1;i<=n;i++)
  12. c[i]=Integer.MAX_VALUE;
  13.  
  14. for(i=1;i<=n;i++)
  15. for(j=0;j<2;j++)
  16. if(m[j]<=i)
  17. {
  18. int min=c[i-m[j]];
  19. if(min!=Integer.MAX_VALUE && min+1<c[i])
  20. {
  21. c[i]=min+1;
  22. fs[i][0]=fs[i-m[j]][0];
  23. fs[i][1]=fs[i-m[j]][1];
  24. fs[i][j]++;
  25. }
  26. }
  27. if(c[n]==Integer.MAX_VALUE) {System.out.print("-1"); return;}
  28. StringBuilder sb=new StringBuilder();
  29. for(i=0;i<fs[n][0];i++)
  30. sb.append(4);
  31. for(i=0;i<fs[n][1];i++)
  32. sb.append(7);
  33. System.out.print(sb);
  34. }
  35. }
Add Comment
Please, Sign In to add comment