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>
#define int long long
using namespace std;
int nbStations, nbExpress, nbSemi;
int tempsLocal, tempsExpress, tempsSemiExpress, tempsMax;
struct Situation
{
int tempsRestant, emplacementsRestant;
Situation(int a, int b) : tempsRestant(a), emplacementsRestant(b) {}
int peutPrendre(void) const
{
return min(emplacementsRestant, 1 + tempsRestant / tempsLocal);
}
Situation prend(void) const
{
int nbPris = peutPrendre();
return {tempsRestant - tempsSemiExpress * nbPris, emplacementsRestant - nbPris};
}
bool operator<(Situation other) const
{
return peutPrendre() < other.peutPrendre();
}
};
signed main(void)
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> nbStations >> nbExpress >> nbSemi;
cin >> tempsLocal >> tempsExpress >> tempsSemiExpress >> tempsMax;
vector<int> posExpress(nbExpress);
for (auto &v : posExpress)
cin >> v;
priority_queue<Situation> pq;
int maxAtteint(-1);
for (int iStation = 0; iStation < nbExpress-1; ++iStation)
{
int tempsRestant = tempsMax - (posExpress[iStation] - 1) * tempsExpress;
if (tempsRestant < 0) continue;
int nbAtteint = min(posExpress[iStation+1] - posExpress[iStation],
1 + tempsRestant / tempsLocal);
maxAtteint += nbAtteint;
tempsRestant -= tempsSemiExpress * nbAtteint;
if (tempsRestant >= 0)
pq.emplace(tempsRestant, posExpress[iStation+1]-posExpress[iStation] - nbAtteint);
}
if (tempsExpress * (nbStations - 1)<= tempsMax)
maxAtteint++;
for (int iter(0); iter < nbSemi - nbExpress and !pq.empty(); ++iter)
{
auto curSituation = pq.top(); pq.pop();
int nbPris = curSituation.peutPrendre();
maxAtteint += nbPris;
auto nxtSituation = curSituation.prend();
if (nxtSituation.tempsRestant >= 0)
pq.push(nxtSituation);
}
cout << maxAtteint << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |