fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int i,n,b25,b50,temp;
  6. cin>>n;
  7. for(i=0;i<n;i++)
  8. {
  9. cin>>temp;
  10. if(temp==25)
  11. b25++;
  12. else if(temp==50)
  13. {
  14. if(b25>0)
  15. {
  16. b25--;
  17. b50++;
  18. }
  19. else
  20. {
  21. cout<<"NO";
  22. return 0;
  23. }
  24.  
  25. }
  26. else if(temp==100)
  27. {
  28. if(b25>0 && b50>0)
  29. {
  30. b25--;
  31. b50--;
  32. }
  33. else if(b25>2)
  34. b25-=3;
  35. else
  36. {
  37. cout<<"NO";
  38. return 0;
  39. }
  40. }
  41. }
  42. cout<<"YES";
  43. return 0;
  44. }
Success #stdin #stdout 0s 3100KB
stdin
2
25 100
stdout
NO