Submission #952679

# Submission time Handle Problem Language Result Execution time Memory
952679 2024-03-24T13:59:31 Z Mohamed_Kachef06 Fuel Station (NOI20_fuelstation) C++17
0 / 100
3000 ms 32472 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 


void doWork(){
    int n , d;
    cin >> n >> d;
    vector<array<int , 3>> v(n+1); 
    vector<array<int , 3>> u(n+1); 
    int arr[n+1] = {};
    // arr[i] = cost to go from i to i+1

    for (int i=  1 ; i <= n ; i++){
        for (int j = 0 ; j < 3 ; j++){
            cin >> v[i][j]; 
        }
    }
    v.push_back({d , 0 , 0});
    sort(v.begin() , v.end());

    for (int i = 1 ; i <= n ; i++){
        u[i] = {v[i][2] , v[i][1] , i}; 
    }
    sort(u.begin() , u.end());

    for (int i = 0 ; i <= n ; i++){
        arr[i] = v[i+1][0] - v[i][0]; 
    }
    int ans = 1e18;
    int id = 1;
    for (int i = 1 ; i <= n ; i++){
        while (id <= n && u[id][0] <= u[i][0]) {arr[u[id][2]]-=u[id][1]; id++;}
        int mx = 0 , sum = 0;
        for (int j = 0 ; j <= n ; j++) {
            sum += arr[j]; 
            mx = max(mx , sum);
        }
        if (mx <= u[id][0]) ans = min(ans , mx);
    }
    cout << ans; 
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    doWork(); 
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3050 ms 32472 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -