Submission #348953

#TimeUsernameProblemLanguageResultExecution timeMemory
348953shrek12357Salesman (IOI09_salesman)C++14
0 / 100
3095 ms15716 KiB
#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;

int dp[MAXN];

int main() {
	//ifstream cin("bcount.in"); ofstream cout("bcount.out");
	int n, u, d, s;
	cin >> n >> u >> d >> s;
	vector<pair<int, pair<int, int>>> nums;
	for (int i = 0; i < n; i++) {
		int t, l, x;
		cin >> t >> l >> x;
		nums.push_back({ t, {l, x} });
	}
	sort(nums.begin(), nums.end());
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			if (s > nums[i].second.first) {
				dp[i] = max(dp[i], nums[i].second.second - (s - nums[i].second.first) * u);
			}
			else {
				dp[i] = max(dp[i], nums[i].second.second - (nums[i].second.first - s) * d);
			}
		}
		else {
			for (int j = 0; j < i; j++) {
				if (nums[j].second.first > nums[i].second.first) {
					dp[i] = max(dp[i], nums[i].second.second - (nums[j].second.first - nums[i].second.first) * u);
				}
				else {
					dp[i] = max(dp[i], 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 << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...