#include "bits/stdc++.h"
#include "overtaking.h"
#define pb push_back
using namespace std;
const int MAXN = 1e3 + 5;
const long long inf = 2e18;
vector<vector<long long> > t(MAXN, vector<long long>(MAXN));
vector<pair<long long, long long> > veclist[MAXN];
vector<int> s;
int n, m, x;
void init(int L, int N, vector<long long> T, vector<int> W, int X, int M, vector<int> S){
for(int i = 0; i < N; i++){
t[i][0] = T[i];
}
for(int j = 1; j < M; j++){
vector<long long> ep(N);
for(int i = 0; i < N; i++){
ep[i] = t[i][j-1] + (long long)(W[i]) * (long long)(S[j] - S[j-1]);
}
vector<pair<long long, long long> > vec;
for(int i = 0; i < N; i++){
vec.pb({t[i][j-1], ep[i]});
}
sort(vec.begin(), vec.end());
for(int i = 1; i < vec.size(); i++){
vec[i].second = max(vec[i].second, vec[i-1].second);
}
veclist[j] = vec;
for(int i = 0; i < N; i++){
long long mval = ep[i];
if(vec[0].first < t[i][j-1]){
int l = 0, r = N-1;
while(l < r){
int mid = (l + r + 1)/2;
if(vec[mid].first >= t[i][j-1]) r = mid - 1;
else l = mid;
}
t[i][j] = max(vec[l].second, ep[i]);
}
else{
t[i][j] = ep[i];
}
/*
for(int cek = 0; cek < N; cek++){
if(t[cek][j-1] < t[i][j-1]){
mval = max(mval, ep[cek]);
}
}
t[i][j] = mval;
*/
}
}
s = S;
n = N;
m = M;
x = X;
}
long long arrival_time(long long Y){
vector<long long> myt(m);
myt[0] = Y;
for(int j = 1; j < m; j++){
long long mval = myt[j-1] + (long long)(x) * (long long)(s[j] - s[j-1]);
if(myt[j-1] <= veclist[j][0].first){
myt[j] = mval;
}
else{
int l = 0, r = n-1;
while(l < r){
int mid = (l + r + 1)/2;
if(veclist[j][mid].first >= myt[j-1]) r = mid - 1;
else l = mid;
}
myt[j] = max(mval, veclist[j][l].second);
}
/*
for(int cek = 0; cek < n; cek++){
if(t[cek][j-1] < myt[j-1]){
mval = max(mval, t[cek][j]);
}
}
myt[j] = mval;
*/
}
return myt[m-1];
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |