Submission #951223

# Submission time Handle Problem Language Result Execution time Memory
951223 2024-03-21T12:18:49 Z NourWael Fuel Station (NOI20_fuelstation) C++17
0 / 100
769 ms 1048576 KB
#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));
   solve(i+1, sum+a[i].second.second);
  
}

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++) {
      |                ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 769 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 692 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 692 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -