ec1117

Untitled

Feb 6th, 2022 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. int solve(int dist) {
  6.   int minspeed;
  7.   cin >> minspeed;
  8.   int lhstravel = 0;
  9.   int rhstravel = 0;
  10.   int timeused = 0;
  11.   for(int currspeed = 1;; currspeed++) {
  12.     lhstravel += currspeed;
  13.     timeused++;
  14.     if(lhstravel + rhstravel >= dist) return timeused;
  15.     if(currspeed >= minspeed) {
  16.       rhstravel += currspeed;
  17.       timeused++;
  18.       if(lhstravel + rhstravel >= dist) return timeused;
  19.     }
  20.   }
  21. }
  22.  
  23. int main() {
  24.   int k, n;
  25.   cin >> k >> n;
  26.   for(int i = 0; i < n; i++) {
  27.     cout << solve(k) << endl;
  28.   }
  29. }
Add Comment
Please, Sign In to add comment