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;
#define int long long
const int INF = 1e18+1e17;
struct line {
int m,k;
line(int m,int k):m(m),k(k){}
int operator()(int x) const {
return m*x+k;
}
};
struct node {
int L,R;
line best;
node *left,*right;
node(int L,int R):L(L),R(R),left(nullptr),right(nullptr),best(0,INF){}
};
void update(node* curr,line x) {
int mid = (curr->L+curr->R)/2;
bool betterL = x(curr->L)<curr->best(curr->L);
bool betterR = x(curr->R)<curr->best(curr->R);
bool betterM = x(mid)<curr->best(mid);
if(betterM) {
swap(curr->best,x);
update(curr,x);
} else if(betterL) {
if(curr->left==nullptr)curr->left=new node(curr->L,mid);
update(curr->left,x);
} else if(betterR) {
if(curr->right==nullptr)curr->right=new node(mid+1,curr->R);
update(curr->right,x);
}
}
int get(node* curr,int x) {
if(curr==nullptr)return INF;
int mid = (curr->L+curr->R)/2;
if(x<=mid)return min(curr->best(x),get(curr->left,x));
return min(curr->best(x),get(curr->right,x));
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int X,N,M,W,T;
cin >> X >> N >> M >> W >> T;
vector<tuple<int,int,int>> arr;
arr.emplace_back(0,0,0);
int iterations = X/T;
X%=T;
arr.emplace_back(X,2,iterations);
for(int i=1;i<=N;i++) {
int S;cin>>S;
arr.emplace_back(S%T,2,S/T);
}
for(int i=1;i<=M;i++) {
int D,C;cin>>D>>C;
arr.emplace_back(D,1,C);
}
sort(arr.begin(), arr.end());
vector<int> DP(arr.size());
DP[0] = (iterations+1)*W;
node *lichao = new node(1,1e18);
int P = 0;
int pref = 0;
for(int i=1;i<arr.size();i++) {
auto [pos,type,c] = arr[i];
if(type==1) {
if(pos<X)DP[i]=(iterations+1)*W + DP[i-1];
else DP[i]=iterations*W + DP[i-1];
update(lichao,{-P,DP[i-1]-pref});
P++;
pref+=c;
continue;
}
DP[i]=DP[i-1];
DP[i]=min(DP[i],get(lichao,c*W)+c*W*P+pref);
}
cout << DP.back() << '\n';
}
Compilation message (stderr)
coach.cpp: In constructor 'node::node(long long int, long long int)':
coach.cpp:19:17: warning: 'node::right' will be initialized after [-Wreorder]
19 | node *left,*right;
| ^~~~~
coach.cpp:18:10: warning: 'line node::best' [-Wreorder]
18 | line best;
| ^~~~
coach.cpp:20:5: warning: when initialized here [-Wreorder]
20 | node(int L,int R):L(L),R(R),left(nullptr),right(nullptr),best(0,INF){}
| ^~~~
coach.cpp: In function 'int32_t main()':
coach.cpp:71:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i=1;i<arr.size();i++) {
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |