6
2025-08-10 15:03:46
发布于:江苏
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h1, m1, h2, m2, n;
char colon;
cin >> h1 >> colon >> m1;
cin >> h2 >> colon >> m2;
cin >> n;
int T_time = (h2 * 60 + m2) - (h1 * 60 + m1);
vector<pair<int, int>> infItems;
vector<vector<int>> multiItems;
bool infinite = false;
for (int i = 0; i < n; i++) {
int t, c, p;
cin >> t >> c >> p;
if (p == 0) {
if (t == 0 && c > 0) {
infinite = true;
} else if (t > 0) {
infItems.push_back({t, c});
}
} else {
if (t == 0) {
if (c > 0) {
multiItems.push_back({0, c * p});
}
} else {
multiItems.push_back({t, c, p});
}
}
}
if (infinite) {
cout << 2000000000 << endl;
return 0;
}
vector<pair<int, int>> binItems;
for (const auto& item : multiItems) {
if (item.size() == 2) {
binItems.push_back({item[0], item[1]});
} else {
int t = item[0];
int c = item[1];
int p = item[2];
int max_p = T_time / t;
if (max_p <= 0) continue;
p = min(p, max_p);
int k = 1;
while (k <= p) {
binItems.push_back({t * k, c * k});
p -= k;
k *= 2;
}
if (p > 0) {
binItems.push_back({t * p, c * p});
}
}
}
vector<int> dp(T_time + 1, 0);
for (const auto& goods : binItems) {
int t = goods.first;
int c = goods.second;
for (int j = T_time; j >= t; j--) {
if (dp[j] < dp[j - t] + c) {
dp[j] = dp[j - t] + c;
}
}
}
for (const auto& item : infItems) {
int t = item.first;
int c = item.second;
for (int j = t; j <= T_time; j++) {
if (dp[j] < dp[j - t] + c) {
dp[j] = dp[j - t] + c;
}
}
}
cout << dp[T_time] << endl;
return 0;
}
这里空空如也
有帮助,赞一个