# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
240106 | MrRobot_28 | Go (COCI18_go) | C++17 | 26 ms | 1280 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair <pair <int, int>, int> a, pair <pair <int, int>, int> b)
{
return a.second < b.second;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, m;
cin >> n >> k >> m;
vector <vector <int> > dp(m, vector <int> (2001, -1e9));
vector <pair <pair <int, int>, int> > mass(m);
for(int i = 0; i < m; i++)
{
cin >> mass[i].first.first >> mass[i].first.second >> mass[i].second;
}
sort(mass.begin(), mass.end(), cmp);
int ans = 0;
for(int i = 0; i < mass.size(); i++)
{
if(abs(mass[i].first.first - k) <= mass[i].second - 1)
{
dp[i][abs(mass[i].first.first - k)] = max(dp[i][abs(mass[i].first.first - k)], mass[i].first.second);
}
for(int j = 0; j < i; j++)
{
for(int t = 0; t <= 2000; t++)
{
int del = abs(mass[i].first.first - mass[j].first.first);
if(del + t >= mass[i].second)
{
continue;
}
dp[i][t + del] = max(dp[i][t + del], dp[j][t] + mass[i].first.second);
}
}
for(int t = 0; t <= 2000; t++)
{
ans = max(ans, dp[i][t]);
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |