Submission #655064

# Submission time Handle Problem Language Result Execution time Memory
655064 2022-11-02T23:18:10 Z horiseun Fuel Station (NOI20_fuelstation) C++11
0 / 100
151 ms 8124 KB
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

#define f first
#define s second

int n, d, a, b, x, l, r, m;
vector<pair<int, vector<pair<int, int>>>> stops;
vector<tuple<int, int, int>> v;

bool valid(int val) {
    for (int i = 1; i < stops.size(); i++) {
        val -= stops[i].f - stops[i - 1].f;
        if (val < 0) return false;
        int rf = 0;
        for (pair<int, int> j : stops[i].s) {
            if (val <= j.s) {
                rf += j.f;
            }
        }
        val += rf;
    }
    return true;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> d;
    for (int i = 0; i < n; i++) {
        cin >> x >> a >> b;
        if (x >= d) continue;
        v.push_back({x, a, b});
    }
    sort(v.begin(), v.end());

    stops.push_back({0, {{0, 0}}});
    for (int i = 0; i < v.size(); i++) {
        if (get<0>(v[i]) == stops[stops.size() - 1].f) {
            stops[stops.size() - 1].s.push_back({get<1>(v[i]), get<2>(v[i])});
        } else {
            stops.push_back({get<0>(v[i]), {{get<1>(v[i]), get<2>(v[i])}}});
        }
    }
    stops.push_back({d, {{0, 0}}});

    l = 0, r = 1e9 + 5;
    while (l + 1 != r) {
        m = (l + r) / 2;
        if (valid(m)) r = m;
        else l = m;
    }

    cout << r << "\n";


}

Compilation message

FuelStation.cpp: In function 'bool valid(int)':
FuelStation.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::vector<std::pair<int, int> > > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = 1; i < stops.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~
FuelStation.cpp: In function 'int main()':
FuelStation.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 151 ms 8112 KB Output is correct
2 Correct 139 ms 8060 KB Output is correct
3 Incorrect 136 ms 8124 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -