#include <bits/stdc++.h>
#define int long long
using namespace std;
int const mxN = 3e5+5;
vector<pair<int,pair<int,int>>>a;
vector<int> pos;
int n,d;
void solve (int i, int sum) {
if(i==n+1) { pos.push_back(sum); return; }
solve(i+1,sum);
solve(i+1, sum+a[i].first-(i? a[i-1].first:0));
//if(i==1) cout<<"here "<<a[i].first-(i? a[i-1].first:0)<<'\n';
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
cin>>n>>d;
a.resize(n+1);
for(int i=0; i<n; i++) cin>>a[i].first>>a[i].second.first>>a[i].second.second;
a[n] = {d,{0,0}};
sort(a.begin(),a.end());
solve(0,0);
sort(pos.begin(),pos.end());
for(int i=0; i<pos.size(); i++) {
int mid = pos[i], now = pos[i];
bool f = 1;
if(mid<a[0].first) f = 0;
else now -= a[0].first;
for(int j=0; j<n; j++) {
if(mid<=a[j].second.second) now += a[j].second.first;
if(now<abs(a[j+1].first-a[j].first)) { f = 0; break; }
now -= abs(a[j+1].first-a[j].first);
}
if(f) { cout<<mid<<'\n'; return 0; }
}
return 0;
}
Compilation message
FuelStation.cpp: In function 'int main()':
FuelStation.cpp:30:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i=0; i<pos.size(); i++) {
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1204 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Runtime error |
907 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Runtime error |
907 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |