gas_problem.cpp 539 B

123456789101112131415161718192021222324252627
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4. int n, k;
  5. cin >> n >> k;
  6. int* station_distance = new int[k+1];
  7. for (int i = 0; i < k+1; ++i) {
  8. cin >> station_distance[i];
  9. if (station_distance[i] > n) {
  10. cout << "No Solution!";
  11. return 0;
  12. }
  13. }
  14. int result = 0, gas_life = n;
  15. for (int i = 0; i < k+1; ++i) {
  16. gas_life -= station_distance[i];
  17. if (gas_life < 0) {
  18. ++result;
  19. gas_life = n - station_distance[i];
  20. }
  21. }
  22. cout << result;
  23. delete [] station_distance;
  24. return 0;
  25. }