Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- #include <algorithm>
- #define task "race"
- #define ld long double
- #define ll long long
- #define ull unsigned long long
- using namespace std;
- const int sizearr = 100003;
- ll k, a[1000006], m;
- int n;
- inline void fastIOfileinput(){
- ios_base:: sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if(fopen(task".inp", "r")){
- freopen(task".inp", "r", stdin);
- freopen(task".out", "w", stdout);
- }
- if(fopen(task".in", "r")){
- freopen(task".in", "r", stdin);
- freopen(task".out", "w", stdout);
- }
- }
- inline void Enter(){
- cin >> k >> n;
- for(int i = 1; i <= n; ++i) cin >> a[i];
- }
- inline void solve(ll x){
- if(k <= x * (x + 1) / 2){
- m = (ll) ceil( (ld)( (ll) sqrt((ld) (8 * k + 1)) - 1LL) * 1.0 / 2);// Cai TH Ä‘ac biet nek
- return;
- }
- // m la thoi gian nha
- m = (ll) sqrt( (ld) (2 * k - 2LL + x * x + x) / 2);
- ll v = (2 * k - 2LL + x * x + x - 2 * m * m) / 2, V = m - x - 1LL;
- m += V + 1LL + (v <= x - 1LL ? (ll)0 : (ll) ceil ( (ld) (v - x + 1LL) * 1.0 / m) );
- }
- int main(){
- fastIOfileinput();
- Enter();
- for(int i = 1; i <= n; ++i){
- solve(a[i]);
- cout << m << (i == n ? "" : "\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement