fork download
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. using namespace std;
  5. float sum1=0.0;
  6. long int n;
  7. void round_a(float a[], int b[])
  8. {
  9. //cout<<"\n Entered.";
  10. sum1=0.0;
  11. for(int p=0; p<n; p++)
  12. {
  13. sum1+=a[p];
  14. //cout<<"\n sum1="<<sum1;
  15. }
  16. if(sum1 == 100.0)
  17. {
  18. printf("YES\n");
  19. }
  20. else
  21. {
  22. for(int p=0; p<n; p++)
  23. {
  24. a[p]-=0.1;
  25. //cout<<"\n a["<<p<<"]="<<a[p]<<"\t b["<<p<<"]="<<b[p];
  26. if(a[p]<b[p]-1)
  27. {
  28. printf("NO\n");
  29. break;
  30. }
  31. sum1=0;
  32. for(int q=0; q<n; q++)
  33. {
  34. sum1+=a[q];
  35. }
  36. //cout<<"\n sum1="<<sum1;
  37. //if(sum1 == 10)
  38. if(fabs(100.0-sum1)<0.0001) //Comparing with epsilon. return fabs(a-b)<EPSILON;
  39. {
  40. printf("YES\n");
  41. break;
  42. }
  43. if(p == n-1)
  44. p=-1;
  45. }
  46. }
  47. }
  48. int main()
  49. {
  50. /*double a=4.1, b=4.9;
  51. if(a>b)
  52. cout<<"\n Greater."<<a+b;
  53. else
  54. cout<<"\n Smaller.";
  55. int c, d;
  56. c=a;
  57. d=b;
  58. cout<<"\n c="<<c<<"\t d="<<d;
  59. int e=c+1.0;
  60. cout<<"\n e="<<e;
  61. if(c<a)
  62. cout<<"\n Lesser than.";*/
  63. int t;
  64. scanf("%d", &t);
  65. for(int i=0; i<t; i++)
  66. {
  67. scanf("%ld", &n);
  68. float a[n];
  69. int b[n];
  70. long int j;
  71. for(j=0; j<n; j++)
  72. {
  73. //cout<<"\n Entered.";
  74. scanf("%f", &a[j]);
  75. b[j]=a[j];
  76. }
  77. round_a(a, b);
  78. }
  79. }
Success #stdin #stdout 0s 2732KB
stdin
3
3
30 30 30
4
25 25 25 25
2
50 51
stdout
NO
YES
YES