Advertisement
Derga

Untitled

Jul 29th, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <algorithm>
  2. #include <string>
  3. #include <utility>
  4. #include <set>
  5. #include <queue>
  6. #include <unordered_set>
  7. #include <map>
  8. #include <iostream>
  9. #include <vector>
  10.  
  11. using namespace std;
  12.  
  13. int main() {
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(nullptr);
  16.  
  17. int tests_count;
  18. cin >> tests_count;
  19. while (tests_count--) {
  20. int n;
  21. cin >> n;
  22. int coins = 0;
  23. bool need = false, have = false;
  24. for (int i = 0; i < n; i++) {
  25. int a;
  26. cin >> a;
  27. if (need) {
  28. if (!have && a) a--;
  29. else coins++;
  30. }
  31. need = !have;
  32. have = a;
  33. }
  34. if (need) coins++;
  35. cout << coins << '\n';
  36. }
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement