fork download
  1. import java.util.Scanner;
  2. import java.util.*;
  3.  
  4. public class Main {
  5. public static void main (String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7. int n = scanner.nextInt();
  8. double s0 = scanner.nextDouble();
  9. double s = scanner.nextDouble();
  10. double [] A = new double[n];
  11. double [] B = new double[n];
  12. if(s0>=s)
  13. System.out.println(0);
  14. else if(n==0)
  15. System.out.println(-1);
  16. else
  17. {
  18. for(int i=0; i<n; i++)
  19. {
  20. double a = scanner.nextDouble();
  21. A[i]=a;
  22. B[i]=A[i];
  23. }
  24. Arrays.sort(B);
  25. int ans=0;
  26. for(int i=n-1; i>=1; i--)
  27. {
  28. if(B[i]>=10.1)
  29. {
  30. if((int)(B[i]-5.1)+s0>=s){
  31. ans++;
  32. System.out.println(ans);
  33. System.exit(0);
  34. }
  35. else
  36. {
  37. ans++;
  38. B[i-1]+=(int)(B[i]-5.1);
  39. }
  40. }
  41. else
  42. {
  43. break;
  44. }
  45. }
  46. if((B[0]>=10.1)&&((int)(B[0]-5.1)+s0>=s))
  47. System.out.println(ans+1);
  48. else
  49. {
  50. Arrays.sort(A);
  51. if(s0>=10.1)
  52. {
  53. A[n-1]+=(int)(s0-5.1);
  54. s0-=(int)(s0-5.1);
  55. s0-=0.1;
  56. ans=1;
  57. for(int i=n-1; i>=1; i--)
  58. {
  59. if(A[i]>=10.1)
  60. {
  61. if((int)(A[i]-5.1)+s0>=s){
  62. ans++;
  63. System.out.println(ans);
  64. System.exit(0);
  65. }
  66. else
  67. {
  68. ans++;
  69. A[i-1]+=(int)(A[i]-5.1);
  70. }
  71. }
  72. else
  73. {
  74. break;
  75. }
  76. }
  77. if((A[0]>=10.1)&&((int)(A[0]-5.1)+s0>=s))
  78. System.out.println(ans+1);
  79. else
  80. System.out.println(-1);
  81. }
  82. else
  83. System.out.println(-1);
  84. }
  85. }
  86. }
  87. }
Success #stdin #stdout 0.08s 2184192KB
stdin
2 10.00 16.00
10.10 6.10
stdout
2