# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1225483 | _rain_ | Long Distance Coach (JOI17_coach) | C++20 | 0 ms | 320 KiB |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=(int)2e5;
const LL INF=(LL)1e18;
int s[N+2];
pair<int,int>d[N+2];
int n,m;
LL w,x,t;
namespace subtask1{
bool check(){
return n<=1000 && m<=1000;
}
LL sum[N+2]={};
LL pre[N+2]={};
int lp[N+2]={};
LL dp[N+2]={};
void main_code(){
s[++n]=x;
for(int i=1;i<=m;++i){
pre[i]=pre[i-1]+d[i].second ,
sum[i]=sum[i-1]+(LL)((x/t)+(x%t>=d[i].first))*w;
}
sort(s+1,s+n+1,[=](int x,int y){
return x%t<y%t;
});
for(int i=1;i<=n;++i) lp[i]=upper_bound(d+1,d+m+1,pair<int,int>(s[i]%t,-1))-d-1;
for(int i=m;i>=1;--i){
for(int j=1;j<=n;++j){
if (s[j]%t>i){
int ez=lp[j];
LL addmore=sum[ez]-sum[i-1]-(pre[ez]-pre[i-1])-((LL)(ez-i+1)*(s[j]/t))*w;
dp[i]=max(dp[i],dp[ez+1]+addmore);
}
}
dp[i]=max(dp[i],dp[i+1]);
}
cout<<sum[m]-dp[1]+(LL)(x/t+(x%t>=0))*w;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0) ; cout.tie(0);
#define task "main"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
cin>>x>>n>>m>>w>>t;
for(int i=1;i<=n;++i) cin>>s[i];
for(int i=1;i<=m;++i) cin>>d[i].first>>d[i].second;
return subtask1::main_code(),0;
return 0;
}
Compilation message (stderr)
# | 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... |