暴力80

 •  19天前


#include <bits/stdc++.h>
using namespace std;
int n, tot = 0, ans = 0;;

int main() {
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		tot += a[i];
	}
	bool flag ;
	while (tot > 0) {
		flag = 0;
		for (int i = 1; i <= n; i++) {
			if (flag) {
				if (a[i] > 0) {
					a[i]--;
					tot--;
				}

				else if (a[i] == 0) {
					flag = 0;
				}
			} else {
				if (a[i] > 0) {
					flag = 1;
					ans++;
					a[i]--;
					tot--;
				} else
					continue;
			}

		}

	}
	cout << ans;
	return 0;
}

评论:

请先登录,才能进行评论