Submission #1113832

# Submission time Handle Problem Language Result Execution time Memory
1113832 2024-11-17T14:28:29 Z Aviansh Fuel Station (NOI20_fuelstation) C++17
79 / 100
3000 ms 21696 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;
}


bool check2(array<long long,3>fuels[], long long f){
    long long F=f;
    //cout << "attempting: " << f << "\n";
    for(long long i = 1;i<=d;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);
    if(d<=1e4){
        array<long long,3>dummy[d+1];
        for(long long i = 0;i<=d;i++){
            dummy[i][0]=i;
            dummy[i][1]=0;
            dummy[i][2]=1e9;
        }
        for(long long i = 0;i<n+2;i++){
            dummy[fuels[i][0]][1]+=fuels[i][1];
            //cout << "added " << fuels[i][1] << " to " << fuels[i][0] << "\n";
            swap(fuels[i][0],fuels[i][2]);
        }
        sort(fuels,fuels+n+2);
        long long curind = 0;
        for(long long i = 0;i<=d;i++){
            while(curind<n+2&&fuels[curind][0]<i){
                dummy[fuels[curind][2]][1]-=fuels[curind][1];
                //cout << "removed " << fuels[curind][1] << " from " << fuels[curind][2] << "\n";
                curind++;
            }
            if(check2(dummy,i)){
                cout << i;
                return 0;
            }
        }
        cout << -1;
        return 0;
    }
    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 504 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 456 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 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 20384 KB Output is correct
2 Correct 115 ms 21184 KB Output is correct
3 Correct 114 ms 21184 KB Output is correct
4 Correct 117 ms 20932 KB Output is correct
5 Correct 126 ms 21696 KB Output is correct
6 Correct 109 ms 20820 KB Output is correct
7 Correct 124 ms 20684 KB Output is correct
8 Correct 116 ms 21308 KB Output is correct
9 Correct 123 ms 21604 KB Output is correct
10 Correct 125 ms 20684 KB Output is correct
11 Correct 112 ms 17344 KB Output is correct
12 Correct 118 ms 21184 KB Output is correct
13 Correct 116 ms 20076 KB Output is correct
14 Correct 111 ms 21280 KB Output is correct
15 Correct 118 ms 17344 KB Output is correct
16 Correct 124 ms 17856 KB Output is correct
17 Correct 118 ms 21696 KB Output is correct
18 Correct 113 ms 21284 KB Output is correct
19 Correct 143 ms 17504 KB Output is correct
20 Correct 114 ms 21184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 592 KB Output is correct
2 Correct 5 ms 848 KB Output is correct
3 Correct 6 ms 1104 KB Output is correct
4 Correct 5 ms 1104 KB Output is correct
5 Correct 5 ms 1104 KB Output is correct
6 Correct 5 ms 1276 KB Output is correct
7 Correct 5 ms 1104 KB Output is correct
8 Correct 38 ms 592 KB Output is correct
9 Correct 41 ms 592 KB Output is correct
10 Correct 32 ms 592 KB Output is correct
11 Correct 17 ms 592 KB Output is correct
12 Correct 51 ms 676 KB Output is correct
13 Correct 23 ms 764 KB Output is correct
14 Correct 47 ms 1268 KB Output is correct
15 Correct 48 ms 1196 KB Output is correct
16 Correct 51 ms 1104 KB Output is correct
17 Correct 49 ms 1272 KB Output is correct
18 Correct 50 ms 1104 KB Output is correct
19 Correct 5 ms 1104 KB Output is correct
20 Correct 5 ms 1236 KB Output is correct
21 Correct 6 ms 1104 KB Output is correct
22 Correct 5 ms 1104 KB Output is correct
23 Correct 5 ms 848 KB Output is correct
24 Correct 5 ms 1104 KB Output is correct
25 Correct 5 ms 992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 592 KB Output is correct
2 Correct 5 ms 848 KB Output is correct
3 Correct 6 ms 1104 KB Output is correct
4 Correct 5 ms 1104 KB Output is correct
5 Correct 5 ms 1104 KB Output is correct
6 Correct 5 ms 1276 KB Output is correct
7 Correct 5 ms 1104 KB Output is correct
8 Correct 38 ms 592 KB Output is correct
9 Correct 41 ms 592 KB Output is correct
10 Correct 32 ms 592 KB Output is correct
11 Correct 17 ms 592 KB Output is correct
12 Correct 51 ms 676 KB Output is correct
13 Correct 23 ms 764 KB Output is correct
14 Correct 47 ms 1268 KB Output is correct
15 Correct 48 ms 1196 KB Output is correct
16 Correct 51 ms 1104 KB Output is correct
17 Correct 49 ms 1272 KB Output is correct
18 Correct 50 ms 1104 KB Output is correct
19 Correct 5 ms 1104 KB Output is correct
20 Correct 5 ms 1236 KB Output is correct
21 Correct 6 ms 1104 KB Output is correct
22 Correct 5 ms 1104 KB Output is correct
23 Correct 5 ms 848 KB Output is correct
24 Correct 5 ms 1104 KB Output is correct
25 Correct 5 ms 992 KB Output is correct
26 Correct 21 ms 592 KB Output is correct
27 Correct 134 ms 17664 KB Output is correct
28 Correct 126 ms 13772 KB Output is correct
29 Correct 130 ms 15552 KB Output is correct
30 Correct 138 ms 16832 KB Output is correct
31 Correct 135 ms 16064 KB Output is correct
32 Correct 139 ms 17088 KB Output is correct
33 Correct 40 ms 592 KB Output is correct
34 Correct 27 ms 692 KB Output is correct
35 Correct 15 ms 592 KB Output is correct
36 Correct 36 ms 592 KB Output is correct
37 Correct 57 ms 760 KB Output is correct
38 Correct 49 ms 592 KB Output is correct
39 Correct 182 ms 17600 KB Output is correct
40 Correct 179 ms 17480 KB Output is correct
41 Correct 186 ms 17600 KB Output is correct
42 Correct 184 ms 17604 KB Output is correct
43 Correct 175 ms 13708 KB Output is correct
44 Correct 154 ms 15472 KB Output is correct
45 Correct 219 ms 16832 KB Output is correct
46 Correct 135 ms 17724 KB Output is correct
47 Correct 127 ms 18880 KB Output is correct
48 Correct 127 ms 18812 KB Output is correct
49 Correct 135 ms 17088 KB Output is correct
50 Correct 130 ms 17348 KB Output is correct
51 Correct 128 ms 17244 KB Output is correct
52 Correct 132 ms 17088 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 504 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 456 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 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 336 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 508 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 504 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 456 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 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 26 ms 592 KB Output is correct
17 Correct 5 ms 848 KB Output is correct
18 Correct 6 ms 1104 KB Output is correct
19 Correct 5 ms 1104 KB Output is correct
20 Correct 5 ms 1104 KB Output is correct
21 Correct 5 ms 1276 KB Output is correct
22 Correct 5 ms 1104 KB Output is correct
23 Correct 38 ms 592 KB Output is correct
24 Correct 41 ms 592 KB Output is correct
25 Correct 32 ms 592 KB Output is correct
26 Correct 17 ms 592 KB Output is correct
27 Correct 51 ms 676 KB Output is correct
28 Correct 23 ms 764 KB Output is correct
29 Correct 47 ms 1268 KB Output is correct
30 Correct 48 ms 1196 KB Output is correct
31 Correct 51 ms 1104 KB Output is correct
32 Correct 49 ms 1272 KB Output is correct
33 Correct 50 ms 1104 KB Output is correct
34 Correct 5 ms 1104 KB Output is correct
35 Correct 5 ms 1236 KB Output is correct
36 Correct 6 ms 1104 KB Output is correct
37 Correct 5 ms 1104 KB Output is correct
38 Correct 5 ms 848 KB Output is correct
39 Correct 5 ms 1104 KB Output is correct
40 Correct 5 ms 992 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 4 ms 1104 KB Output is correct
43 Correct 4 ms 1068 KB Output is correct
44 Correct 5 ms 1104 KB Output is correct
45 Correct 5 ms 1184 KB Output is correct
46 Correct 4 ms 1104 KB Output is correct
47 Correct 5 ms 1104 KB Output is correct
48 Correct 37 ms 592 KB Output is correct
49 Correct 43 ms 592 KB Output is correct
50 Correct 41 ms 592 KB Output is correct
51 Correct 20 ms 760 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 34 ms 592 KB Output is correct
54 Correct 5 ms 1104 KB Output is correct
55 Correct 5 ms 1072 KB Output is correct
56 Correct 5 ms 1104 KB Output is correct
57 Correct 4 ms 1204 KB Output is correct
58 Correct 5 ms 1276 KB Output is correct
59 Correct 5 ms 1104 KB Output is correct
60 Correct 5 ms 1104 KB Output is correct
61 Correct 5 ms 1072 KB Output is correct
62 Correct 5 ms 1104 KB Output is correct
63 Correct 4 ms 916 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 504 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 456 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 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 114 ms 20384 KB Output is correct
17 Correct 115 ms 21184 KB Output is correct
18 Correct 114 ms 21184 KB Output is correct
19 Correct 117 ms 20932 KB Output is correct
20 Correct 126 ms 21696 KB Output is correct
21 Correct 109 ms 20820 KB Output is correct
22 Correct 124 ms 20684 KB Output is correct
23 Correct 116 ms 21308 KB Output is correct
24 Correct 123 ms 21604 KB Output is correct
25 Correct 125 ms 20684 KB Output is correct
26 Correct 112 ms 17344 KB Output is correct
27 Correct 118 ms 21184 KB Output is correct
28 Correct 116 ms 20076 KB Output is correct
29 Correct 111 ms 21280 KB Output is correct
30 Correct 118 ms 17344 KB Output is correct
31 Correct 124 ms 17856 KB Output is correct
32 Correct 118 ms 21696 KB Output is correct
33 Correct 113 ms 21284 KB Output is correct
34 Correct 143 ms 17504 KB Output is correct
35 Correct 114 ms 21184 KB Output is correct
36 Correct 26 ms 592 KB Output is correct
37 Correct 5 ms 848 KB Output is correct
38 Correct 6 ms 1104 KB Output is correct
39 Correct 5 ms 1104 KB Output is correct
40 Correct 5 ms 1104 KB Output is correct
41 Correct 5 ms 1276 KB Output is correct
42 Correct 5 ms 1104 KB Output is correct
43 Correct 38 ms 592 KB Output is correct
44 Correct 41 ms 592 KB Output is correct
45 Correct 32 ms 592 KB Output is correct
46 Correct 17 ms 592 KB Output is correct
47 Correct 51 ms 676 KB Output is correct
48 Correct 23 ms 764 KB Output is correct
49 Correct 47 ms 1268 KB Output is correct
50 Correct 48 ms 1196 KB Output is correct
51 Correct 51 ms 1104 KB Output is correct
52 Correct 49 ms 1272 KB Output is correct
53 Correct 50 ms 1104 KB Output is correct
54 Correct 5 ms 1104 KB Output is correct
55 Correct 5 ms 1236 KB Output is correct
56 Correct 6 ms 1104 KB Output is correct
57 Correct 5 ms 1104 KB Output is correct
58 Correct 5 ms 848 KB Output is correct
59 Correct 5 ms 1104 KB Output is correct
60 Correct 5 ms 992 KB Output is correct
61 Correct 21 ms 592 KB Output is correct
62 Correct 134 ms 17664 KB Output is correct
63 Correct 126 ms 13772 KB Output is correct
64 Correct 130 ms 15552 KB Output is correct
65 Correct 138 ms 16832 KB Output is correct
66 Correct 135 ms 16064 KB Output is correct
67 Correct 139 ms 17088 KB Output is correct
68 Correct 40 ms 592 KB Output is correct
69 Correct 27 ms 692 KB Output is correct
70 Correct 15 ms 592 KB Output is correct
71 Correct 36 ms 592 KB Output is correct
72 Correct 57 ms 760 KB Output is correct
73 Correct 49 ms 592 KB Output is correct
74 Correct 182 ms 17600 KB Output is correct
75 Correct 179 ms 17480 KB Output is correct
76 Correct 186 ms 17600 KB Output is correct
77 Correct 184 ms 17604 KB Output is correct
78 Correct 175 ms 13708 KB Output is correct
79 Correct 154 ms 15472 KB Output is correct
80 Correct 219 ms 16832 KB Output is correct
81 Correct 135 ms 17724 KB Output is correct
82 Correct 127 ms 18880 KB Output is correct
83 Correct 127 ms 18812 KB Output is correct
84 Correct 135 ms 17088 KB Output is correct
85 Correct 130 ms 17348 KB Output is correct
86 Correct 128 ms 17244 KB Output is correct
87 Correct 132 ms 17088 KB Output is correct
88 Correct 1 ms 336 KB Output is correct
89 Correct 1 ms 336 KB Output is correct
90 Correct 1 ms 336 KB Output is correct
91 Correct 1 ms 336 KB Output is correct
92 Correct 1 ms 336 KB Output is correct
93 Correct 1 ms 336 KB Output is correct
94 Correct 1 ms 336 KB Output is correct
95 Correct 1 ms 336 KB Output is correct
96 Correct 1 ms 336 KB Output is correct
97 Correct 1 ms 464 KB Output is correct
98 Correct 1 ms 336 KB Output is correct
99 Correct 1 ms 464 KB Output is correct
100 Correct 1 ms 336 KB Output is correct
101 Correct 1 ms 336 KB Output is correct
102 Correct 1 ms 508 KB Output is correct
103 Correct 1 ms 336 KB Output is correct
104 Correct 4 ms 1104 KB Output is correct
105 Correct 4 ms 1068 KB Output is correct
106 Correct 5 ms 1104 KB Output is correct
107 Correct 5 ms 1184 KB Output is correct
108 Correct 4 ms 1104 KB Output is correct
109 Correct 5 ms 1104 KB Output is correct
110 Correct 37 ms 592 KB Output is correct
111 Correct 43 ms 592 KB Output is correct
112 Correct 41 ms 592 KB Output is correct
113 Correct 20 ms 760 KB Output is correct
114 Correct 1 ms 336 KB Output is correct
115 Correct 34 ms 592 KB Output is correct
116 Correct 5 ms 1104 KB Output is correct
117 Correct 5 ms 1072 KB Output is correct
118 Correct 5 ms 1104 KB Output is correct
119 Correct 4 ms 1204 KB Output is correct
120 Correct 5 ms 1276 KB Output is correct
121 Correct 5 ms 1104 KB Output is correct
122 Correct 5 ms 1104 KB Output is correct
123 Correct 5 ms 1072 KB Output is correct
124 Correct 5 ms 1104 KB Output is correct
125 Correct 4 ms 916 KB Output is correct
126 Correct 5 ms 1104 KB Output is correct
127 Correct 5 ms 1104 KB Output is correct
128 Correct 1 ms 336 KB Output is correct
129 Correct 118 ms 20416 KB Output is correct
130 Correct 124 ms 20928 KB Output is correct
131 Correct 134 ms 21440 KB Output is correct
132 Correct 122 ms 20896 KB Output is correct
133 Correct 127 ms 20928 KB Output is correct
134 Correct 124 ms 21696 KB Output is correct
135 Correct 24 ms 692 KB Output is correct
136 Correct 25 ms 592 KB Output is correct
137 Correct 35 ms 676 KB Output is correct
138 Correct 15 ms 592 KB Output is correct
139 Correct 1 ms 336 KB Output is correct
140 Correct 25 ms 592 KB Output is correct
141 Correct 128 ms 21592 KB Output is correct
142 Correct 137 ms 21184 KB Output is correct
143 Correct 123 ms 21468 KB Output is correct
144 Correct 131 ms 21440 KB Output is correct
145 Correct 137 ms 21484 KB Output is correct
146 Execution timed out 3063 ms 19904 KB Time limit exceeded
147 Halted 0 ms 0 KB -