fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void updateValues(int dryed, int &totalDryedDays, int &totalUndryedDays) {
  5. if (dryed == 0) {
  6. totalDryedDays = 0;
  7. ++totalUndryedDays;
  8. } else {
  9. totalUndryedDays = 0;
  10. ++totalDryedDays;
  11. }
  12. }
  13.  
  14. int main() {
  15. int x, y, z, n;
  16. cin >> x >> y >> z >> n;
  17. int totalDryedDays = 0, totalUndryedDays = 0;
  18. for (int i = 1; i <= n; ++i) {
  19. int dryed;
  20. cin >> dryed;
  21. x += dryed;
  22. updateValues(dryed, totalDryedDays, totalUndryedDays);
  23. if (totalDryedDays == y) {
  24. x += z;
  25. totalDryedDays = 0;
  26. } else if (totalUndryedDays == y) {
  27. break;
  28. }
  29. }
  30. if (totalUndryedDays == y) {
  31. cout << "A MURIT";
  32. } else {
  33. cout << x;
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5316KB
stdin
1 3 4 6
1 1 1 0 0 1
stdout
9