# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
348965 | shrek12357 | Salesman (IOI09_salesman) | C++14 | 3078 ms | 26440 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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <iomanip>
#include <bitset>
//#include "network.h"
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0);
const int MAXN = 1e5 + 5;
ll dp[MAXN];
int main() {
//ifstream cin("bcount.in"); ofstream cout("bcount.out");
ll n, u, d, s;
cin >> n >> u >> d >> s;
vector<pair<ll, pair<ll, ll>>> nums;
for (int i = 0; i < n; i++) {
ll t, l, x;
cin >> t >> l >> x;
nums.push_back({ t, {l, x} });
}
nums.push_back({ 0, {s, 0} });
nums.push_back({ 1e12, {s, 0} });
sort(nums.begin(), nums.end());
for (int i = 0; i < nums.size(); i++) {
dp[i] = -1e12;
}
dp[0] = 0;
for (int i = 0; i < nums.size(); i++) {
for (int j = 0; j < i; j++) {
if (nums[j].second.first > nums[i].second.first) {
dp[i] = max(dp[i], dp[j] + nums[i].second.second - (nums[j].second.first - nums[i].second.first) * u);
}
else {
dp[i] = max(dp[i], dp[j] + nums[i].second.second - (nums[i].second.first - nums[j].second.first) * d);
}
}
}
/*int ans = 0;
for (int i = 0; i < n; i++) {
if (nums[i].second.first > s) {
ans = max(ans, dp[i] - (nums[i].second.first - s) * u);
}
else {
ans = max(ans, dp[i] - (s - nums[i].second.first) * d);
}
}*/
cout << dp[nums.size() - 1] << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |