結果

問題 No.1430 Coup de Coupon
ユーザー startcppstartcpp
提出日時 2021-03-14 14:20:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 38,912 KB
最終ジャッジ日時 2024-04-23 21:50:26
合計ジャッジ時間 2,055 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 17 ms
23,680 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 18 ms
23,680 KB
testcase_07 AC 16 ms
23,552 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 19 ms
13,952 KB
testcase_10 AC 28 ms
22,784 KB
testcase_11 AC 36 ms
29,312 KB
testcase_12 AC 42 ms
34,816 KB
testcase_13 AC 47 ms
38,016 KB
testcase_14 AC 44 ms
38,912 KB
testcase_15 AC 42 ms
38,144 KB
testcase_16 AC 37 ms
35,200 KB
testcase_17 AC 28 ms
30,592 KB
testcase_18 AC 47 ms
37,888 KB
testcase_19 AC 46 ms
38,144 KB
testcase_20 AC 40 ms
38,144 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 5 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

void chmin(int &a, int b) { a = min(a, b); }

int INF = 1e+9;
int n, C;
int p[5000];
vector<int> hiki;
vector<int> wari;
int dp[5001][5001];

signed main() {
	int i, j;
	
	cin >> n >> C;
	rep(i, n) cin >> p[i];
	sort(p, p + n, greater<int>());
	
	rep(i, C) {
		int t, x; cin >> t >> x;
		if (t == 1) { hiki.push_back(x); }
		else { wari.push_back(x); }
	}
	sort(hiki.begin(), hiki.end(), greater<int>());
	sort(wari.begin(), wari.end(), greater<int>());
	
	rep(i, hiki.size() + 1) rep(j, wari.size() + 1) dp[i][j] = INF;
	dp[0][0] = 0;
	
	rep(i, hiki.size() + 1) {
		rep(j, wari.size() + 1) {
			if (i + j >= n) continue;
			if (i < hiki.size()) {
				chmin(dp[i + 1][j], dp[i][j] + max(p[i + j] - hiki[i], 0));
			}
			if (j < wari.size()) {
				chmin(dp[i][j + 1], dp[i][j] + p[i + j] * (100 - wari[j]) / 100);
			}
		}
	}
	
	if (C >= n) {
		int ans = INF;
		rep(i, hiki.size() + 1) {
			int j = n - i;
			if (j > wari.size()) continue;
			chmin(ans, dp[i][j]);
		}
		cout << ans << endl;
	}
	else {
		int ans = INF;
		rep(i, hiki.size() + 1) {
			int j = C - i;
			if (j > wari.size()) continue;
			chmin(ans, dp[i][j]);
		}
		
		for (i = C; i < n; i++) {
			ans += p[i];
		}
		cout << ans << endl;
	}
	return 0;
}
0