結果

問題 No.710 チーム戦
ユーザー しらっ亭しらっ亭
提出日時 2018-04-18 03:09:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,208 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 169,664 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-09 11:16:15
合計ジャッジ時間 9,080 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,752 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2,784 ms
4,380 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)

int n;
pair<int, int> P[200];
int ans;
int aa, bb;
int rest[200];

void dfs(int i) {
	int ma = max(aa, bb);
	int mi = min(aa, bb);

	if (ma + (rest[i] - (ma - mi)) / 2 >= ans) return;

	if (i == n) {
		if (ans > ma) {
			ans = ma;
		}
		return;
	}

	aa += P[i].first;
	dfs(i+1);
	aa -= P[i].first;

	bb += P[i].second;
	dfs(i+1);
	bb -= P[i].second;
}

int solve() {
	{
		int aa = 0, bb = 0;
		rep(i, n) {
			if (P[i].first < P[i].second) {
				aa += P[i].first;
			}
			else if (P[i].first > P[i].second) {
				bb += P[i].second;
			}
			else {
				if (aa < bb) aa += P[i].first;
				else bb += P[i].second;
			}
		}
		ans = max(aa, bb);
	}

	auto cmp = [&](pair<int, int> lhs, decltype(lhs) rhs) -> bool {
		return lhs.first + lhs.second > rhs.first + rhs.second;
	};
	sort(P, P+n, cmp);

	rrep(i, n-1) {
		rest[i] = rest[i+1] + min(P[i+1].first, P[i+1].second);
	}

	dfs(0);

	return ans;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	cin >> n;

	rep(i, n) {
		cin >> P[i].first >> P[i].second;
	}

	int ans = solve();

	cout << ans << endl;

	return 0;
}
0