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 "overtaking.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vec vector
struct Line {
int a;
int b;
};
const int MXN = 105;
const int MXQ = 105;
const int MXM = 105;
vec<int32_t> s;
int n;
int x;
struct Bus {
int t;
int w;
int i;
};
vec<Bus> buses;
void init(int32_t L, int32_t N, std::vector<long long> T, std::vector<int32_t> W, int32_t X, int32_t M, std::vector<int32_t> S)
{
s = S;
n = N;
x = X;
buses = vec<Bus>(n+1);
for(int i = 0; i<n; i++) {
buses[i] = {T[i], W[i], i};
}
return;
}
long long arrival_time(long long Y)
{
auto buses_copy = buses;
buses[n] = {Y, x, n};
for(int i = 1; i<s.size(); i++) {
sort(buses.begin(), buses.end(), [](auto& b1, auto& b2) {return b1.t == b2.t ? (b1.w < b2.w) : b1.t<b2.t;});
int mxt = 0;
for(auto& bus : buses) {
bus.t = max(mxt, bus.t+bus.w*(s[i]-s[i-1]));
mxt = max(bus.t, mxt);
}
}
for(auto bus : buses) {
if(bus.i == n) {
buses = buses_copy;
return bus.t;
}
}
return -1;
}
Compilation message (stderr)
overtaking.cpp: In function 'long long int arrival_time(long long int)':
overtaking.cpp:51:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i = 1; i<s.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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |