src2020/4091_garden/garden.cpp

50 lines
1.2 KiB
C++

#include <algorithm>
#include <iostream>
using namespace std;
int tou[100] = { 0 }, wei[100] = { 0 }, lan[100] = { 0 }, alan[1001] = { 0 }, ans = 0;
void huan(int* ze, int* na)
{
int u = *ze;
*ze = *na;
*na = u;
}
void pan(int yi, int er)
{
if (tou[er] < tou[yi]) {
huan(&tou[yi], &tou[er]);
huan(&wei[yi], &wei[er]);
huan(&lan[yi], &lan[er]);
}
}
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tou[i] >> wei[i] >> lan[i];
}
for (int i = 0; i <= n - 2; i++) {
for (int j = i + 1; j < n; j++) {
pan(i, j);
}
}
for (int i = 0; i < n; i++) {
//cout << tou[i] << " " << wei[i] << " " << lan[i] << endl;
for (int j = 1; j <= ans; j++) {
if (alan[j] < tou[i]) {
// cout << alan[j] << " " << lan[i] << endl;
alan[j] = wei[i];
lan[i]--;
}
if (lan[i] == 0) {
break;
}
}
for (int j = 1; j <= lan[i]; j++) {
alan[++ans] = wei[i];
}
//cout << ans << endl << endl;
}
cout << ans;
}