#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
using namespace std;
#define ll long long
//cin.tie(0);
//ios_base::sync_with_stdio(0);
struct p {
int room;
int candy;
int time;
};
bool comp(p a, p b) {
return a.room < b.room;
}
int n, d, m;
vector<p> nums;
int LCalc(int i, int j, int idx) {
int tot = 0;
int LTime = d - nums[i].room;
for (int k = idx; k >= i; k--) {
int t = (d - nums[k].room);
if (nums[k].time > t) {
tot += nums[k].candy;
}
}
for (int k = idx; k <= j; k++) {
int t = LTime + nums[k].room - d;
if (nums[k].time > t) {
tot += nums[k].candy;
}
}
return tot;
}
int RCalc(int i, int j, int idx) {
int tot = 0;
int RTime = nums[j].room - d;
for (int k = idx; k <= j; k++) {
int t = (nums[k].room - d);
if (nums[k].time > t) {
tot += nums[k].candy;
}
}
for (int k = idx; k >= i; k--) {
int t = RTime + d - nums[k].room;
if (nums[k].time > t) {
tot += nums[k].candy;
}
}
return tot;
}
int main() {
cin >> n >> d >> m;
nums.push_back({ d, 0, 0 });
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
nums.push_back({ a, b, c });
}
m++;
sort(nums.begin(), nums.end(), comp);
int idx = 0;
p c = { d, 0, 0 };
for (int i = 0; i < m; i++) {
if (nums[i].room == d && nums[i].candy == 0) {
idx = i;
}
}
int best = 0;
for (int i = idx; i >= 0; i--) {
for (int j = idx; j < m; j++) {
int totL = 0, totR = 0;
int LTime = d - nums[i].room, RTime = nums[j].room - d;
best = max(LCalc(i, j, idx), best);
best = max(RCalc(i, j, idx), best);
}
}
cout << best << endl;
}
Compilation message
go.cpp: In function 'int main()':
go.cpp:89:8: warning: unused variable 'totL' [-Wunused-variable]
89 | int totL = 0, totR = 0;
| ^~~~
go.cpp:89:18: warning: unused variable 'totR' [-Wunused-variable]
89 | int totL = 0, totR = 0;
| ^~~~
go.cpp:90:8: warning: unused variable 'LTime' [-Wunused-variable]
90 | int LTime = d - nums[i].room, RTime = nums[j].room - d;
| ^~~~~
go.cpp:90:34: warning: unused variable 'RTime' [-Wunused-variable]
90 | int LTime = d - nums[i].room, RTime = nums[j].room - d;
| ^~~~~
go.cpp:80:4: warning: unused variable 'c' [-Wunused-variable]
80 | p c = { d, 0, 0 };
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
276 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |