Submission #697320

# Submission time Handle Problem Language Result Execution time Memory
697320 2023-02-09T08:44:51 Z tengiz05 Long Distance Coach (JOI17_coach) C++17
0 / 100
1 ms 324 KB
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    i64 _X, n, m, w, t;
    std::cin >> _X >> n >> m >> w >> t;
    
    std::vector<i64> a(n + 2);
    std::map<i64, i64> end_map, cnt_end;
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
    }
    a[n + 1] = _X;
    std::sort(a.begin(), a.end());
    for (int i = 1; i <= n + 1; i++) {
        if (!end_map.count(a[i] % t)) {
            end_map[a[i] % t] = a[i];
            cnt_end[a[i] % t]++;
        }
    }
    
    std::vector<std::pair<i64, i64>> p(m);
    std::set<std::pair<i64, i64>> s;
    for (int i = 0; i < m; i++) {
        std::cin >> p[i].first >> p[i].second;
        s.insert({p[i].first, p[i].second});
    }
    std::sort(p.begin(), p.end());
    
    i64 total = w * (_X / t + 1 - cnt_end[0]);
    for (int i = 0; i < m; i++) {
        total += w * ((_X - p[i].first) / t + 1 - cnt_end[p[i].first]);
    }
    
    for (int i = 1; i <= n + 1; i++) {
        i64 cost = 0;
        int best = 0;
        i64 bestcost = 0;
        i64 cur = a[i] % t - 1;
        i64 curcur = cur;
        int done = 0;
        //~ std::cout << a[i] << ": " << a[i] % t << "\n";
        while (curcur > 0) {
            auto it = s.upper_bound({curcur + 1, -1});
            if (it == s.begin()) break;
            it--;
            done++;
            cost += it->second;
            cost -= w * ((_X - (a[i] - a[i] % t + it->first)) / t + 1 - cnt_end[it->first]);
            //~ std::cout << "_" << it->first << " " << (_X - (a[i] - a[i] % t + it->first)) << " got us " << ((_X - (a[i] - a[i] % t + it->first)) / t + 1 - cnt_end[it->first]) << "\n";
            if (bestcost > cost) {
                bestcost = cost;
                best = done;
            }
            curcur = it->first - 1;
        }
        //~ std::cout << best << " :: " << bestcost << "\n\n";
        total += bestcost;
        while (best--) {
            auto it = s.upper_bound({cur + 1, -1});
            it--;
            s.erase(it);
        }
        cnt_end[a[i] % t]--;
    }
    
    std::cout << total << "\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 316 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -