結果

問題 No.297 カードの数式
ユーザー kurenaifkurenaif
提出日時 2016-06-07 18:27:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,175 bytes
コンパイル時間 939 ms
コンパイル使用メモリ 72,632 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 06:00:30
合計ジャッジ時間 1,798 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

vector<string> num;
vector<string> op;
vector<int> nums;

int GetMax(int p, int m) {
	int res = 0;
	for (int i = 0; i < nums.size(); ++i) {
		if (p > 0) {
			res += nums[i];
			--p;
		}
		else if (m > 0) {
			res -= nums[i];
			--m;
		}
	}
	return res;
}

int GetMin(int p, int m) {
	int res = 0;
	for (int i = 0; i < nums.size(); ++i) {
		if (m > 0) {
			res -= nums[i];
			--m;
		}
		else if (p > 0) {
			res += nums[i];
			--p;
		}
	}
	return res;
}

int main(void) {
	int N; cin >> N;
	int opCnt = 0;
	int pCnt = 1;
	int mCnt = 0;
	for (int i = 0; i < N; ++i) {
		string s; cin >> s;
		if (s == "+") ++pCnt;
		else if (s == "-") ++mCnt;
		else
			num.push_back(s);
	}
	int numCnt = pCnt + mCnt;

	sort(num.begin(), num.end());
	reverse(num.begin(), num.end());

	string s;
	for (int i = 0; i < (num.size() - (pCnt+mCnt-1)); ++i) {
		s += num[i];
	}
	nums.push_back(atoi(s.c_str()));
	for (int i = num.size() - (pCnt+mCnt-1); i < num.size(); ++i) {
		nums.push_back(atoi(num[i].c_str()));
	}

	cout << GetMax(pCnt, mCnt) << " " << GetMin(pCnt, mCnt) << endl;

	return 0;
}
0