Submission #1106035

# Submission time Handle Problem Language Result Execution time Memory
1106035 2024-10-29T03:00:48 Z huyngodzz Fuel Station (NOI20_fuelstation) C++14
100 / 100
376 ms 68488 KB
    ///huynhocute123///
#include<bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define pb push_back
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = b; i >= a; --i)
#define ALL(v) v.begin(),v.end()
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
//random_device rd;
//mt19937 rng(rd());
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
#define int long long
const int maxN = 1e6 + 9 ;
const int  modd = 1e9 + 7;
const int base = 2309;
const int MAX = 1e9+9;
const double pi = 3.14159265358979323846;
const double rad = 3.14159265358979323846 /180;
void minimize(int &u, int v){
    if(v < u) u = v;
}
void maximize(int &u, int v){
    if(v > u) u = v;
}
int n, k, t, m, res, a[maxN], d, lazy[4 *maxN], st[4 *maxN];
int l, r;
bool vis[maxN];
vector<int> e[maxN];
struct node{
    int x, di , mn;
}fuel[maxN];
bool cmp(node a , node b){
    return a.x <  b.x;
}
void push(int id ){
    if(lazy[id] == 0 )return;
    st[id*2] +=lazy[id];
    st[id * 2 +1] += lazy[id];
    lazy[id * 2] += lazy[id];
    lazy[id*2 +1 ] +=lazy[id];
    lazy[id] =0;
}
void upd(int id ,int l ,int r  ,int u ,int v, int val){
    if(v <  l || u > r)return;
    if(u <= l && r <= v){
        st[id]+= val;
        lazy[id] +=val;
        return;
    }
    int mid = (l + r)/2;
    push(id);
    upd(id*2 ,l ,mid ,u ,v, val);
    upd(id*2 + 1 ,mid + 1, r ,u ,v, val);
    st[id] = max(st[id*2] ,st[id*2 +1]);
}

int get(int id ,int l ,int r ,int u ,int v){
    if(v < l || u > r)return - MAX;
    if(u <= l && r<= v)return st[id];
    int mid =( l +  r ) /2;
    push(id);
    return max(get(id*2 , l ,mid ,u ,v) , get(id*2 + 1, mid +1 ,r ,u , v) );
}
bool cmpp(pii a ,pii b){
    if(a.F != b.F)return a.F > b.F;
    return a.S > b.S;
}
void solve(){
    cin >> n >> d;
    for(int i= 1;i <= n ;i++){
        cin >> fuel[i].x >>fuel[i].di >> fuel[i].mn;
    }
    sort(fuel +1 , fuel +1 +  n , cmp);
    vector<pii> ed;
    for(int i =1;i <= n ;i++){
        upd(1, 1, n , i , i ,fuel[i].x);
    ed.pb({fuel[i].mn , i});
    }
    sort(ALL(ed), cmpp);
    res = d;
    long long tot = 0;
    for(auto [x,y] : ed){
            tot += fuel[y].di;
            upd(1, 1 ,n , y + 1, n , -fuel[y].di);
            long long tmp = max(st[1] , d -tot);
            tmp  = max(tmp , 0LL);
            if(tmp <= x){
                minimize(res, tmp);
            }

    }
    cout << res;


}
signed main(){
//    freopen("name.inp","r",stdin);
//    freopen("name.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    inp("task.inp");
    t = 1;
   // cin >> t;
    while( t-- )solve();
    cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ;


}

Compilation message

FuelStation.cpp: In function 'void solve()':
FuelStation.cpp:89:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   89 |     for(auto [x,y] : ed){
      |              ^
FuelStation.cpp: In function 'int main()':
FuelStation.cpp:12:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~
FuelStation.cpp:108:5: note: in expansion of macro 'inp'
  108 |     inp("task.inp");
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31056 KB Output is correct
2 Correct 5 ms 31056 KB Output is correct
3 Correct 6 ms 31056 KB Output is correct
4 Correct 5 ms 31056 KB Output is correct
5 Correct 5 ms 31056 KB Output is correct
6 Correct 6 ms 31056 KB Output is correct
7 Correct 6 ms 31056 KB Output is correct
8 Correct 6 ms 31056 KB Output is correct
9 Correct 5 ms 31056 KB Output is correct
10 Correct 5 ms 31056 KB Output is correct
11 Correct 6 ms 31056 KB Output is correct
12 Correct 6 ms 31056 KB Output is correct
13 Correct 6 ms 31056 KB Output is correct
14 Correct 6 ms 31056 KB Output is correct
15 Correct 5 ms 31056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 241 ms 65432 KB Output is correct
2 Correct 225 ms 67516 KB Output is correct
3 Correct 213 ms 63076 KB Output is correct
4 Correct 210 ms 67784 KB Output is correct
5 Correct 201 ms 63164 KB Output is correct
6 Correct 221 ms 67260 KB Output is correct
7 Correct 217 ms 63164 KB Output is correct
8 Correct 207 ms 63276 KB Output is correct
9 Correct 227 ms 63164 KB Output is correct
10 Correct 209 ms 63280 KB Output is correct
11 Correct 211 ms 61244 KB Output is correct
12 Correct 231 ms 63420 KB Output is correct
13 Correct 211 ms 63272 KB Output is correct
14 Correct 217 ms 63164 KB Output is correct
15 Correct 216 ms 63280 KB Output is correct
16 Correct 224 ms 65832 KB Output is correct
17 Correct 212 ms 68064 KB Output is correct
18 Correct 209 ms 63164 KB Output is correct
19 Correct 204 ms 67512 KB Output is correct
20 Correct 199 ms 63280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31056 KB Output is correct
2 Correct 11 ms 32080 KB Output is correct
3 Correct 12 ms 32080 KB Output is correct
4 Correct 11 ms 31956 KB Output is correct
5 Correct 11 ms 31952 KB Output is correct
6 Correct 11 ms 31956 KB Output is correct
7 Correct 11 ms 32120 KB Output is correct
8 Correct 5 ms 29008 KB Output is correct
9 Correct 4 ms 29188 KB Output is correct
10 Correct 5 ms 29008 KB Output is correct
11 Correct 5 ms 29008 KB Output is correct
12 Correct 5 ms 31056 KB Output is correct
13 Correct 4 ms 29008 KB Output is correct
14 Correct 11 ms 31924 KB Output is correct
15 Correct 11 ms 31972 KB Output is correct
16 Correct 11 ms 31956 KB Output is correct
17 Correct 11 ms 32128 KB Output is correct
18 Correct 12 ms 32080 KB Output is correct
19 Correct 11 ms 31956 KB Output is correct
20 Correct 11 ms 31956 KB Output is correct
21 Correct 12 ms 32080 KB Output is correct
22 Correct 11 ms 32020 KB Output is correct
23 Correct 11 ms 31956 KB Output is correct
24 Correct 11 ms 31956 KB Output is correct
25 Correct 11 ms 32028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 31056 KB Output is correct
2 Correct 11 ms 32080 KB Output is correct
3 Correct 12 ms 32080 KB Output is correct
4 Correct 11 ms 31956 KB Output is correct
5 Correct 11 ms 31952 KB Output is correct
6 Correct 11 ms 31956 KB Output is correct
7 Correct 11 ms 32120 KB Output is correct
8 Correct 5 ms 29008 KB Output is correct
9 Correct 4 ms 29188 KB Output is correct
10 Correct 5 ms 29008 KB Output is correct
11 Correct 5 ms 29008 KB Output is correct
12 Correct 5 ms 31056 KB Output is correct
13 Correct 4 ms 29008 KB Output is correct
14 Correct 11 ms 31924 KB Output is correct
15 Correct 11 ms 31972 KB Output is correct
16 Correct 11 ms 31956 KB Output is correct
17 Correct 11 ms 32128 KB Output is correct
18 Correct 12 ms 32080 KB Output is correct
19 Correct 11 ms 31956 KB Output is correct
20 Correct 11 ms 31956 KB Output is correct
21 Correct 12 ms 32080 KB Output is correct
22 Correct 11 ms 32020 KB Output is correct
23 Correct 11 ms 31956 KB Output is correct
24 Correct 11 ms 31956 KB Output is correct
25 Correct 11 ms 32028 KB Output is correct
26 Correct 5 ms 31056 KB Output is correct
27 Correct 258 ms 61216 KB Output is correct
28 Correct 362 ms 58172 KB Output is correct
29 Correct 303 ms 55436 KB Output is correct
30 Correct 288 ms 52844 KB Output is correct
31 Correct 376 ms 55400 KB Output is correct
32 Correct 286 ms 65560 KB Output is correct
33 Correct 6 ms 29008 KB Output is correct
34 Correct 6 ms 29008 KB Output is correct
35 Correct 6 ms 29060 KB Output is correct
36 Correct 6 ms 29196 KB Output is correct
37 Correct 5 ms 31056 KB Output is correct
38 Correct 7 ms 29020 KB Output is correct
39 Correct 306 ms 66348 KB Output is correct
40 Correct 274 ms 63276 KB Output is correct
41 Correct 264 ms 63164 KB Output is correct
42 Correct 247 ms 63172 KB Output is correct
43 Correct 251 ms 67004 KB Output is correct
44 Correct 237 ms 64816 KB Output is correct
45 Correct 212 ms 64448 KB Output is correct
46 Correct 267 ms 63276 KB Output is correct
47 Correct 214 ms 65724 KB Output is correct
48 Correct 194 ms 64956 KB Output is correct
49 Correct 276 ms 65156 KB Output is correct
50 Correct 258 ms 64700 KB Output is correct
51 Correct 245 ms 64188 KB Output is correct
52 Correct 238 ms 63164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31056 KB Output is correct
2 Correct 5 ms 31056 KB Output is correct
3 Correct 6 ms 31056 KB Output is correct
4 Correct 5 ms 31056 KB Output is correct
5 Correct 5 ms 31056 KB Output is correct
6 Correct 6 ms 31056 KB Output is correct
7 Correct 6 ms 31056 KB Output is correct
8 Correct 6 ms 31056 KB Output is correct
9 Correct 5 ms 31056 KB Output is correct
10 Correct 5 ms 31056 KB Output is correct
11 Correct 6 ms 31056 KB Output is correct
12 Correct 6 ms 31056 KB Output is correct
13 Correct 6 ms 31056 KB Output is correct
14 Correct 6 ms 31056 KB Output is correct
15 Correct 5 ms 31056 KB Output is correct
16 Correct 5 ms 31056 KB Output is correct
17 Correct 5 ms 29008 KB Output is correct
18 Correct 5 ms 29008 KB Output is correct
19 Correct 5 ms 29008 KB Output is correct
20 Correct 5 ms 29008 KB Output is correct
21 Correct 4 ms 29008 KB Output is correct
22 Correct 6 ms 29008 KB Output is correct
23 Correct 5 ms 31056 KB Output is correct
24 Correct 5 ms 29008 KB Output is correct
25 Correct 5 ms 29008 KB Output is correct
26 Correct 4 ms 29008 KB Output is correct
27 Correct 5 ms 29008 KB Output is correct
28 Correct 5 ms 29008 KB Output is correct
29 Correct 4 ms 29008 KB Output is correct
30 Correct 5 ms 29008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31056 KB Output is correct
2 Correct 5 ms 31056 KB Output is correct
3 Correct 6 ms 31056 KB Output is correct
4 Correct 5 ms 31056 KB Output is correct
5 Correct 5 ms 31056 KB Output is correct
6 Correct 6 ms 31056 KB Output is correct
7 Correct 6 ms 31056 KB Output is correct
8 Correct 6 ms 31056 KB Output is correct
9 Correct 5 ms 31056 KB Output is correct
10 Correct 5 ms 31056 KB Output is correct
11 Correct 6 ms 31056 KB Output is correct
12 Correct 6 ms 31056 KB Output is correct
13 Correct 6 ms 31056 KB Output is correct
14 Correct 6 ms 31056 KB Output is correct
15 Correct 5 ms 31056 KB Output is correct
16 Correct 5 ms 31056 KB Output is correct
17 Correct 11 ms 32080 KB Output is correct
18 Correct 12 ms 32080 KB Output is correct
19 Correct 11 ms 31956 KB Output is correct
20 Correct 11 ms 31952 KB Output is correct
21 Correct 11 ms 31956 KB Output is correct
22 Correct 11 ms 32120 KB Output is correct
23 Correct 5 ms 29008 KB Output is correct
24 Correct 4 ms 29188 KB Output is correct
25 Correct 5 ms 29008 KB Output is correct
26 Correct 5 ms 29008 KB Output is correct
27 Correct 5 ms 31056 KB Output is correct
28 Correct 4 ms 29008 KB Output is correct
29 Correct 11 ms 31924 KB Output is correct
30 Correct 11 ms 31972 KB Output is correct
31 Correct 11 ms 31956 KB Output is correct
32 Correct 11 ms 32128 KB Output is correct
33 Correct 12 ms 32080 KB Output is correct
34 Correct 11 ms 31956 KB Output is correct
35 Correct 11 ms 31956 KB Output is correct
36 Correct 12 ms 32080 KB Output is correct
37 Correct 11 ms 32020 KB Output is correct
38 Correct 11 ms 31956 KB Output is correct
39 Correct 11 ms 31956 KB Output is correct
40 Correct 11 ms 32028 KB Output is correct
41 Correct 6 ms 31068 KB Output is correct
42 Correct 12 ms 32148 KB Output is correct
43 Correct 12 ms 32380 KB Output is correct
44 Correct 12 ms 31944 KB Output is correct
45 Correct 12 ms 32128 KB Output is correct
46 Correct 12 ms 32212 KB Output is correct
47 Correct 12 ms 32224 KB Output is correct
48 Correct 5 ms 29008 KB Output is correct
49 Correct 5 ms 29008 KB Output is correct
50 Correct 5 ms 29008 KB Output is correct
51 Correct 5 ms 29008 KB Output is correct
52 Correct 5 ms 31056 KB Output is correct
53 Correct 5 ms 29008 KB Output is correct
54 Correct 13 ms 31956 KB Output is correct
55 Correct 12 ms 31956 KB Output is correct
56 Correct 12 ms 31968 KB Output is correct
57 Correct 12 ms 31956 KB Output is correct
58 Correct 12 ms 32268 KB Output is correct
59 Correct 12 ms 32212 KB Output is correct
60 Correct 11 ms 32236 KB Output is correct
61 Correct 11 ms 31956 KB Output is correct
62 Correct 12 ms 32196 KB Output is correct
63 Correct 12 ms 32212 KB Output is correct
64 Correct 13 ms 31956 KB Output is correct
65 Correct 12 ms 31956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31056 KB Output is correct
2 Correct 5 ms 31056 KB Output is correct
3 Correct 6 ms 31056 KB Output is correct
4 Correct 5 ms 31056 KB Output is correct
5 Correct 5 ms 31056 KB Output is correct
6 Correct 6 ms 31056 KB Output is correct
7 Correct 6 ms 31056 KB Output is correct
8 Correct 6 ms 31056 KB Output is correct
9 Correct 5 ms 31056 KB Output is correct
10 Correct 5 ms 31056 KB Output is correct
11 Correct 6 ms 31056 KB Output is correct
12 Correct 6 ms 31056 KB Output is correct
13 Correct 6 ms 31056 KB Output is correct
14 Correct 6 ms 31056 KB Output is correct
15 Correct 5 ms 31056 KB Output is correct
16 Correct 241 ms 65432 KB Output is correct
17 Correct 225 ms 67516 KB Output is correct
18 Correct 213 ms 63076 KB Output is correct
19 Correct 210 ms 67784 KB Output is correct
20 Correct 201 ms 63164 KB Output is correct
21 Correct 221 ms 67260 KB Output is correct
22 Correct 217 ms 63164 KB Output is correct
23 Correct 207 ms 63276 KB Output is correct
24 Correct 227 ms 63164 KB Output is correct
25 Correct 209 ms 63280 KB Output is correct
26 Correct 211 ms 61244 KB Output is correct
27 Correct 231 ms 63420 KB Output is correct
28 Correct 211 ms 63272 KB Output is correct
29 Correct 217 ms 63164 KB Output is correct
30 Correct 216 ms 63280 KB Output is correct
31 Correct 224 ms 65832 KB Output is correct
32 Correct 212 ms 68064 KB Output is correct
33 Correct 209 ms 63164 KB Output is correct
34 Correct 204 ms 67512 KB Output is correct
35 Correct 199 ms 63280 KB Output is correct
36 Correct 5 ms 31056 KB Output is correct
37 Correct 11 ms 32080 KB Output is correct
38 Correct 12 ms 32080 KB Output is correct
39 Correct 11 ms 31956 KB Output is correct
40 Correct 11 ms 31952 KB Output is correct
41 Correct 11 ms 31956 KB Output is correct
42 Correct 11 ms 32120 KB Output is correct
43 Correct 5 ms 29008 KB Output is correct
44 Correct 4 ms 29188 KB Output is correct
45 Correct 5 ms 29008 KB Output is correct
46 Correct 5 ms 29008 KB Output is correct
47 Correct 5 ms 31056 KB Output is correct
48 Correct 4 ms 29008 KB Output is correct
49 Correct 11 ms 31924 KB Output is correct
50 Correct 11 ms 31972 KB Output is correct
51 Correct 11 ms 31956 KB Output is correct
52 Correct 11 ms 32128 KB Output is correct
53 Correct 12 ms 32080 KB Output is correct
54 Correct 11 ms 31956 KB Output is correct
55 Correct 11 ms 31956 KB Output is correct
56 Correct 12 ms 32080 KB Output is correct
57 Correct 11 ms 32020 KB Output is correct
58 Correct 11 ms 31956 KB Output is correct
59 Correct 11 ms 31956 KB Output is correct
60 Correct 11 ms 32028 KB Output is correct
61 Correct 5 ms 31056 KB Output is correct
62 Correct 258 ms 61216 KB Output is correct
63 Correct 362 ms 58172 KB Output is correct
64 Correct 303 ms 55436 KB Output is correct
65 Correct 288 ms 52844 KB Output is correct
66 Correct 376 ms 55400 KB Output is correct
67 Correct 286 ms 65560 KB Output is correct
68 Correct 6 ms 29008 KB Output is correct
69 Correct 6 ms 29008 KB Output is correct
70 Correct 6 ms 29060 KB Output is correct
71 Correct 6 ms 29196 KB Output is correct
72 Correct 5 ms 31056 KB Output is correct
73 Correct 7 ms 29020 KB Output is correct
74 Correct 306 ms 66348 KB Output is correct
75 Correct 274 ms 63276 KB Output is correct
76 Correct 264 ms 63164 KB Output is correct
77 Correct 247 ms 63172 KB Output is correct
78 Correct 251 ms 67004 KB Output is correct
79 Correct 237 ms 64816 KB Output is correct
80 Correct 212 ms 64448 KB Output is correct
81 Correct 267 ms 63276 KB Output is correct
82 Correct 214 ms 65724 KB Output is correct
83 Correct 194 ms 64956 KB Output is correct
84 Correct 276 ms 65156 KB Output is correct
85 Correct 258 ms 64700 KB Output is correct
86 Correct 245 ms 64188 KB Output is correct
87 Correct 238 ms 63164 KB Output is correct
88 Correct 5 ms 31056 KB Output is correct
89 Correct 5 ms 29008 KB Output is correct
90 Correct 5 ms 29008 KB Output is correct
91 Correct 5 ms 29008 KB Output is correct
92 Correct 5 ms 29008 KB Output is correct
93 Correct 4 ms 29008 KB Output is correct
94 Correct 6 ms 29008 KB Output is correct
95 Correct 5 ms 31056 KB Output is correct
96 Correct 5 ms 29008 KB Output is correct
97 Correct 5 ms 29008 KB Output is correct
98 Correct 4 ms 29008 KB Output is correct
99 Correct 5 ms 29008 KB Output is correct
100 Correct 5 ms 29008 KB Output is correct
101 Correct 4 ms 29008 KB Output is correct
102 Correct 5 ms 29008 KB Output is correct
103 Correct 6 ms 31068 KB Output is correct
104 Correct 12 ms 32148 KB Output is correct
105 Correct 12 ms 32380 KB Output is correct
106 Correct 12 ms 31944 KB Output is correct
107 Correct 12 ms 32128 KB Output is correct
108 Correct 12 ms 32212 KB Output is correct
109 Correct 12 ms 32224 KB Output is correct
110 Correct 5 ms 29008 KB Output is correct
111 Correct 5 ms 29008 KB Output is correct
112 Correct 5 ms 29008 KB Output is correct
113 Correct 5 ms 29008 KB Output is correct
114 Correct 5 ms 31056 KB Output is correct
115 Correct 5 ms 29008 KB Output is correct
116 Correct 13 ms 31956 KB Output is correct
117 Correct 12 ms 31956 KB Output is correct
118 Correct 12 ms 31968 KB Output is correct
119 Correct 12 ms 31956 KB Output is correct
120 Correct 12 ms 32268 KB Output is correct
121 Correct 12 ms 32212 KB Output is correct
122 Correct 11 ms 32236 KB Output is correct
123 Correct 11 ms 31956 KB Output is correct
124 Correct 12 ms 32196 KB Output is correct
125 Correct 12 ms 32212 KB Output is correct
126 Correct 13 ms 31956 KB Output is correct
127 Correct 12 ms 31956 KB Output is correct
128 Correct 5 ms 31056 KB Output is correct
129 Correct 269 ms 66380 KB Output is correct
130 Correct 274 ms 63424 KB Output is correct
131 Correct 268 ms 59068 KB Output is correct
132 Correct 283 ms 59068 KB Output is correct
133 Correct 293 ms 67600 KB Output is correct
134 Correct 274 ms 63172 KB Output is correct
135 Correct 7 ms 29008 KB Output is correct
136 Correct 5 ms 29008 KB Output is correct
137 Correct 5 ms 29020 KB Output is correct
138 Correct 5 ms 29008 KB Output is correct
139 Correct 6 ms 31056 KB Output is correct
140 Correct 5 ms 29008 KB Output is correct
141 Correct 276 ms 63272 KB Output is correct
142 Correct 281 ms 63156 KB Output is correct
143 Correct 271 ms 63164 KB Output is correct
144 Correct 270 ms 67768 KB Output is correct
145 Correct 287 ms 65580 KB Output is correct
146 Correct 284 ms 68276 KB Output is correct
147 Correct 263 ms 63280 KB Output is correct
148 Correct 263 ms 67004 KB Output is correct
149 Correct 277 ms 68488 KB Output is correct
150 Correct 202 ms 67884 KB Output is correct
151 Correct 196 ms 63268 KB Output is correct
152 Correct 269 ms 63160 KB Output is correct
153 Correct 267 ms 67420 KB Output is correct
154 Correct 255 ms 64188 KB Output is correct
155 Correct 268 ms 64288 KB Output is correct