# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1225508 | _rain_ | Long Distance Coach (JOI17_coach) | C++20 | 2095 ms | 8228 KiB |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=(int)2e5;
const LL INF=(LL)1e18;
LL s[N+2];
pair<LL,int>d[N+2];
int n,m;
LL w,x,t;
namespace subtask1{
bool check(){
return n<=1000 && m<=1000;
}
LL pre[N+2]={};
int need[N+2]={};
LL dp[N+2]={};
void main_code(){
sort(d+1,d+m+1,[&](pair<LL,int> x,pair<LL,int> y){
return x.first % t < y.first % t;
});
s[++n]=x;
sort(s+1,s+n+1);
for(int i=1;i<=m;++i) pre[i]=pre[i-1]+d[i].second;
for(int i=1;i<=n;++i) {
int pos=upper_bound(d+1,d+m+1,pair<LL,int>(s[i]%t,-1))-d-1;
if (need[pos]==0) need[pos]=i;
}
dp[0]=(LL)(x/t)*w+w;
for(int i=1;i<=m;++i){
dp[i]=dp[i-1]+(LL)(x/t+(x%t>=d[i].first))*w;
if (need[i]){
for(int j=0;j<i;++j){
dp[i]=min(dp[i],dp[j]+pre[i]-pre[j]+(LL)(s[need[i]]/t)*(i-j)*w);
}
}
}
cout<<dp[m]<<'\n';
}
}
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;
}
컴파일 시 표준 에러 (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... |