Submission #1113793

# Submission time Handle Problem Language Result Execution time Memory
1113793 2024-11-17T13:07:18 Z Aviansh Fuel Station (NOI20_fuelstation) C++17
67 / 100
3000 ms 21960 KB
#include <bits/stdc++.h>

using namespace std;

long long n,d;
bool check(array<long long,3>fuels[], long long f){
    long long F=f;
    //cout << "attempting: " << f << "\n";
    for(long long i = 1;i<n+2;i++){
      //  cout << "at station " << i << "\n";
        //cout << fuels[i][0] << " " << fuels[i][1] << " " << fuels[i][2] << "\n";
        f-=fuels[i][0]-fuels[i-1][0];
      //  cout << "current fuel: " << f << "\n";
        if(f<0){
            return 0;
        }
        if(F>fuels[i][2]){
            continue;
        }
        f+=fuels[i][1];
        //cout << "fueled from station " << i << "\n";
    }
    return 1;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n>>d;
    array<long long,3> fuels[n+2];
    fuels[0][0]=0;
    fuels[0][1]=0;
    fuels[0][2]=d+5;
    fuels[n+1][0]=d;
    fuels[n+1][1]=0;
    fuels[n+1][2]=d+5;
    vector<long long>bs;
    for(long long i = 1;i<=n;i++){
        long long a,b,x;
        cin >> x >> a >> b;
        fuels[i][0]=x;
        fuels[i][1]=a;
        fuels[i][2]=b;
        bs.push_back(b);
    }
    bs.push_back(d);
    sort(bs.begin(),bs.end());
    sort(fuels,fuels+n+2);
    long long hi = d;
    for(long long i : bs){
        if(check(fuels,i)){
            hi=i;
            break;
        }
    }
    long long lo = 0;
    while(lo<hi){
        long long mid = (lo+hi)/2;
        if(check(fuels,mid)){
            hi=mid;
        }
        else{
            lo=mid+1;
        }
    }
    cout << lo;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 13776 KB Output is correct
2 Correct 123 ms 21208 KB Output is correct
3 Correct 119 ms 21200 KB Output is correct
4 Correct 129 ms 21184 KB Output is correct
5 Correct 122 ms 21696 KB Output is correct
6 Correct 114 ms 20712 KB Output is correct
7 Correct 109 ms 20672 KB Output is correct
8 Correct 117 ms 21204 KB Output is correct
9 Correct 136 ms 21952 KB Output is correct
10 Correct 131 ms 20672 KB Output is correct
11 Correct 115 ms 20680 KB Output is correct
12 Correct 117 ms 21440 KB Output is correct
13 Correct 111 ms 20684 KB Output is correct
14 Correct 111 ms 21180 KB Output is correct
15 Correct 114 ms 21184 KB Output is correct
16 Correct 118 ms 21716 KB Output is correct
17 Correct 117 ms 21960 KB Output is correct
18 Correct 118 ms 21260 KB Output is correct
19 Correct 122 ms 21180 KB Output is correct
20 Correct 144 ms 21184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 508 KB Output is correct
2 Correct 4 ms 848 KB Output is correct
3 Correct 4 ms 848 KB Output is correct
4 Correct 3 ms 848 KB Output is correct
5 Correct 3 ms 848 KB Output is correct
6 Correct 4 ms 848 KB Output is correct
7 Correct 4 ms 848 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 4 ms 848 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 848 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 4 ms 848 KB Output is correct
22 Correct 3 ms 892 KB Output is correct
23 Correct 3 ms 848 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 508 KB Output is correct
2 Correct 4 ms 848 KB Output is correct
3 Correct 4 ms 848 KB Output is correct
4 Correct 3 ms 848 KB Output is correct
5 Correct 3 ms 848 KB Output is correct
6 Correct 4 ms 848 KB Output is correct
7 Correct 4 ms 848 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 4 ms 848 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 848 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 4 ms 848 KB Output is correct
22 Correct 3 ms 892 KB Output is correct
23 Correct 3 ms 848 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 93 ms 13760 KB Output is correct
28 Correct 92 ms 13760 KB Output is correct
29 Correct 95 ms 13564 KB Output is correct
30 Correct 89 ms 13760 KB Output is correct
31 Correct 96 ms 13760 KB Output is correct
32 Correct 98 ms 13760 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 504 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 104 ms 13776 KB Output is correct
40 Correct 111 ms 13760 KB Output is correct
41 Correct 96 ms 13760 KB Output is correct
42 Correct 97 ms 13776 KB Output is correct
43 Correct 102 ms 13760 KB Output is correct
44 Execution timed out 3067 ms 13760 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 528 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 508 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 848 KB Output is correct
19 Correct 3 ms 848 KB Output is correct
20 Correct 3 ms 848 KB Output is correct
21 Correct 4 ms 848 KB Output is correct
22 Correct 4 ms 848 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 4 ms 848 KB Output is correct
30 Correct 4 ms 848 KB Output is correct
31 Correct 4 ms 848 KB Output is correct
32 Correct 4 ms 848 KB Output is correct
33 Correct 4 ms 848 KB Output is correct
34 Correct 4 ms 848 KB Output is correct
35 Correct 3 ms 748 KB Output is correct
36 Correct 4 ms 848 KB Output is correct
37 Correct 3 ms 892 KB Output is correct
38 Correct 3 ms 848 KB Output is correct
39 Correct 4 ms 848 KB Output is correct
40 Correct 4 ms 848 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 4 ms 848 KB Output is correct
43 Correct 4 ms 1104 KB Output is correct
44 Correct 7 ms 1104 KB Output is correct
45 Correct 5 ms 1092 KB Output is correct
46 Correct 5 ms 1104 KB Output is correct
47 Correct 5 ms 1104 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 336 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 5 ms 1204 KB Output is correct
55 Correct 5 ms 1104 KB Output is correct
56 Correct 5 ms 1192 KB Output is correct
57 Correct 5 ms 1104 KB Output is correct
58 Correct 7 ms 1104 KB Output is correct
59 Correct 5 ms 1104 KB Output is correct
60 Correct 5 ms 1272 KB Output is correct
61 Correct 5 ms 1104 KB Output is correct
62 Correct 5 ms 1104 KB Output is correct
63 Correct 5 ms 1104 KB Output is correct
64 Correct 5 ms 1104 KB Output is correct
65 Correct 5 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 116 ms 13776 KB Output is correct
17 Correct 123 ms 21208 KB Output is correct
18 Correct 119 ms 21200 KB Output is correct
19 Correct 129 ms 21184 KB Output is correct
20 Correct 122 ms 21696 KB Output is correct
21 Correct 114 ms 20712 KB Output is correct
22 Correct 109 ms 20672 KB Output is correct
23 Correct 117 ms 21204 KB Output is correct
24 Correct 136 ms 21952 KB Output is correct
25 Correct 131 ms 20672 KB Output is correct
26 Correct 115 ms 20680 KB Output is correct
27 Correct 117 ms 21440 KB Output is correct
28 Correct 111 ms 20684 KB Output is correct
29 Correct 111 ms 21180 KB Output is correct
30 Correct 114 ms 21184 KB Output is correct
31 Correct 118 ms 21716 KB Output is correct
32 Correct 117 ms 21960 KB Output is correct
33 Correct 118 ms 21260 KB Output is correct
34 Correct 122 ms 21180 KB Output is correct
35 Correct 144 ms 21184 KB Output is correct
36 Correct 1 ms 508 KB Output is correct
37 Correct 4 ms 848 KB Output is correct
38 Correct 4 ms 848 KB Output is correct
39 Correct 3 ms 848 KB Output is correct
40 Correct 3 ms 848 KB Output is correct
41 Correct 4 ms 848 KB Output is correct
42 Correct 4 ms 848 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 4 ms 848 KB Output is correct
50 Correct 4 ms 848 KB Output is correct
51 Correct 4 ms 848 KB Output is correct
52 Correct 4 ms 848 KB Output is correct
53 Correct 4 ms 848 KB Output is correct
54 Correct 4 ms 848 KB Output is correct
55 Correct 3 ms 748 KB Output is correct
56 Correct 4 ms 848 KB Output is correct
57 Correct 3 ms 892 KB Output is correct
58 Correct 3 ms 848 KB Output is correct
59 Correct 4 ms 848 KB Output is correct
60 Correct 4 ms 848 KB Output is correct
61 Correct 1 ms 336 KB Output is correct
62 Correct 93 ms 13760 KB Output is correct
63 Correct 92 ms 13760 KB Output is correct
64 Correct 95 ms 13564 KB Output is correct
65 Correct 89 ms 13760 KB Output is correct
66 Correct 96 ms 13760 KB Output is correct
67 Correct 98 ms 13760 KB Output is correct
68 Correct 1 ms 336 KB Output is correct
69 Correct 1 ms 336 KB Output is correct
70 Correct 1 ms 336 KB Output is correct
71 Correct 1 ms 336 KB Output is correct
72 Correct 1 ms 504 KB Output is correct
73 Correct 1 ms 336 KB Output is correct
74 Correct 104 ms 13776 KB Output is correct
75 Correct 111 ms 13760 KB Output is correct
76 Correct 96 ms 13760 KB Output is correct
77 Correct 97 ms 13776 KB Output is correct
78 Correct 102 ms 13760 KB Output is correct
79 Execution timed out 3067 ms 13760 KB Time limit exceeded
80 Halted 0 ms 0 KB -