【CS Round #48 (Div. 2 only)】Water Volume

【链接】h在这里写链接


【题意】


在这里写题意

【题解】


枚举0在哪个位置就好。

【错的次数】


0

【反思】


在这了写反思

【代码】

#include <bits/stdc++.h>
using namespace std;


const int N = 1e3;


int t[N + 10], a[N + 10], n;


int f(int pos) {
	int ma = 0;
	int x = 0;
	for (int i = pos; i >= 1; i--) {
		if (t[i] == 1)
			x += a[i];
		else
			x -= a[i];
		if (x < 0) return -1;
		ma = max(ma, x);
	}
	x = 0;
	for (int i = pos + 1; i <= n; i++) {
		if (t[i] == 1)
			x -= a[i];
		else
			x += a[i];
		if (x < 0) return -1;
		ma = max(ma, x);
	}
	return ma;
}


int main() {
	//freopen("F:\rush.txt", "r", stdin);
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> t[i] >> a[i];
	int ma = 0;
	for (int i = 0; i <= n; i++) {
		int ju = f(i);
		if (ju == -1) continue;
		ma = max(ma, ju);
	}
	cout << ma << endl;


	return 0;
}


原文地址:https://www.cnblogs.com/AWCXV/p/7626021.html