Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 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.     if(k <= x * (x + 1) / 2){
  37.         m = (ll) ceil( (ld)( (ll) sqrt((ld) (8 * k + 1)) - 1LL) * 1.0  / 2);// Cai TH Ä‘ac biet nek
  38.         return;
  39.     }
  40. // m la thoi gian nha
  41.     m = (ll) sqrt( (ld) (2 * k - 2LL + x * x + x) / 2);
  42.     ll v = (2 * k - 2LL + x * x + x - 2 * m * m) / 2, V = m - x - 1LL;
  43.     m += V + 1LL + (v <= x - 1LL ? (ll)0 : (ll) ceil ( (ld) (v - x + 1LL) * 1.0 / m) );
  44. }
  45.  
  46. int main(){
  47.     fastIOfileinput();
  48.     Enter();
  49.     for(int i = 1; i <= n; ++i){
  50.         solve(a[i]);
  51.         cout << m << (i == n ? "" : "\n");
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement