結果

問題 No.107 モンスター
ユーザー hotpepsihotpepsi
提出日時 2016-08-08 23:36:23
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,223 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 67,608 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 22:20:26
合計ジャッジ時間 1,406 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>

using namespace std;

typedef vector<int> IntVec;

int main(int argc, char *argv[])
{
	int N;
	cin >> N;
	IntVec g, b;
	for (int i = 0; i < N; ++i) {
		int d;
		cin >> d;
		if (d > 0) {
			g.push_back(d);
		} else {
			b.push_back(-d);
		}
	}
	sort(g.begin(), g.end());
	sort(b.begin(), b.end());
	int hp = 100, hpm = 100;
	int i, j;
	while (b.size() > 0) {
		for (i = 0; i != b.size(); ++i) {
			if (hp > b[i]) {
				break;
			}
		}
		if (i != b.size()) {
			hp -= b[i];
			hpm += 100;
			b.erase(b.begin() + i);
		} else if (g.size() <= 0) {
			hp = 0;
			break;
		} else {
			int m = 1 << 30, xi = g.size() - 1, xj = -1;
			for (i = 0; i != g.size(); ++i) {
				int x = min(hp + g[i], hpm);
				int y = x + g[i] - hpm;
				for (j = b.size() - 1; j >= 0; --j) {
					if (x > b[j] && y < m) {
						m = y;
						xi = i;
						xj = j;
						break;
					}
				}
			}
			hp = min(hp + g[xi], hpm);
			g.erase(g.begin() + xi);
			if (xj >= 0) {
				hp -= b[xj];
				hpm += 100;
				b.erase(b.begin() + xj);
			}
		}
	}
	if (b.size() <= 0) {
		for (i = 0; i != g.size(); ++i) {
			hp = min(hp + g[i], hpm);
		}
	}
	cout << hp << endl;
	return 0;
}
0