# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
98231 | SuperJava | Salesman (IOI09_salesman) | C++17 | 1077 ms | 10348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng);}
//endfold
#define N (500005)
#define MOD (1000000000l + 7l)
#define OO (1050000000)
#define OOL (1100000000000000000)
vector<tuple<int,int,int>> a;
// i, l
int dp[2][N];
int main(){
//fold
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cout << setprecision(10);
//endfold
int n,u,d,s;
cin >> n >> u >> d >> s;
int mx = s,mn = s;
for (int i = 0; i < n; ++i){
int t,l,m;
cin >> t >> l >> m;
mx = max(mx,l);
mn = min(mn,l);
a.emplace_back(t,l,m);
}
sort(a.begin(), a.end(),[](auto a,auto b){
return get<0>(a) < get<0>(b);
});
for (int i = mn; i < s; ++i){
dp[1][i] = -(s-i)*d;
}
for (int i = s+1; i <= mx; ++i){
dp[1][i] = -(i-s)*u;
}
int g = 1;
for (int i = n-1; i >= 0; --i){
int loc = get<1>(a[i]);
int mon = get<2>(a[i]);
for (int l = mn; l <= mx; ++l){
int dist = 0;
if(l < loc) dist = (loc-l)*d;
else dist = (l-loc)*u;
dp[!g][l] = max(dp[g][l],mon+dp[g][loc]-dist);
}
g = !g;
}
cout << dp[g][s];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |