Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <string>
- #include <utility>
- #include <set>
- #include <queue>
- #include <unordered_set>
- #include <map>
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int tests_count;
- cin >> tests_count;
- while (tests_count--) {
- int n;
- cin >> n;
- int coins = 0;
- bool need = false, have = false;
- for (int i = 0; i < n; i++) {
- int a;
- cin >> a;
- if (need) {
- if (!have && a) a--;
- else coins++;
- }
- need = !have;
- have = a;
- }
- if (need) coins++;
- cout << coins << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement