Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include <algorithm>
  5. #define task "race"
  6. #define ld long double
  7. #define ll long long
  8. #define ull unsigned long long
  9.  
  10. using namespace std;
  11. const int sizearr = 100003;
  12.  
  13. ll k, a[1000006], m;
  14. int n;
  15.  
  16. inline void fastIOfileinput(){
  17.     ios_base:: sync_with_stdio(0);
  18.     cin.tie(0);
  19.     cout.tie(0);
  20.     if(fopen(task".inp", "r")){
  21.         freopen(task".inp", "r", stdin);
  22.         freopen(task".out", "w", stdout);
  23.     }
  24.     if(fopen(task".in", "r")){
  25.         freopen(task".in", "r", stdin);
  26.         freopen(task".out", "w", stdout);
  27.     }
  28. }
  29.  
  30. inline void Enter(){
  31.     cin >> k >> n;
  32.     for(int i = 1; i <= n; ++i) cin >> a[i];
  33. }
  34.  
  35. inline void solve(ll x){
  36.     m = (ll) sqrt( (ld) (2 * k - 2LL + x * x + x) / 2); // Tim ong v lon nhat ma Bessie le dc van toc v roi xuong x + 1 truoc khi di
  37.                                                         //duoc k kilometers
  38.     ll v = (2 * k - 2LL + x * x + x - 2 * m * m) / 2, V = m - x - 1LL; // Nhu vay, thoi gian tam co la v + (v - x - 1)
  39.     m += V + 1LL + (v <= x - 1LL ? (ll)0 : (ll) ceil ( (ld) (v - x + 1LL) * 1.0 / m) ); // Con du mot doan chua di het, ta di not
  40.     // Vi truoc khi den diem cuoi, Bessie da dat van toc x, nen neu nhu quang duong can di con lai ma  <= x - 1 thi se di het ma kcan
  41.     //them chut thoi gian nao, nguoc lai ta di het x, van con 1 quang duong can di, nen ta tinh not
  42. }
  43.  
  44. int main(){
  45.     fastIOfileinput();
  46.     Enter();
  47.     for(int i = 1; i <= n; ++i){
  48.         solve(a[i]);
  49.         cout << m << (i == n ? "" : "\n");
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement