# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
308759 |
2020-10-01T21:12:38 Z |
shrek12357 |
Go (COCI18_go) |
C++14 |
|
1 ms |
384 KB |
#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 - 1;
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 = 2*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 - 1;
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 = 2*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:90:8: warning: unused variable 'totL' [-Wunused-variable]
90 | int totL = 0, totR = 0;
| ^~~~
go.cpp:90:18: warning: unused variable 'totR' [-Wunused-variable]
90 | int totL = 0, totR = 0;
| ^~~~
go.cpp:91:8: warning: unused variable 'LTime' [-Wunused-variable]
91 | int LTime = d - nums[i].room, RTime = nums[j].room - d;
| ^~~~~
go.cpp:91:34: warning: unused variable 'RTime' [-Wunused-variable]
91 | int LTime = d - nums[i].room, RTime = nums[j].room - d;
| ^~~~~
go.cpp:81:4: warning: unused variable 'c' [-Wunused-variable]
81 | p c = { d, 0, 0 };
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |