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){
- 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
- //duoc k kilometers
- 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)
- 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
- // 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
- //them chut thoi gian nao, nguoc lai ta di het x, van con 1 quang duong can di, nen ta tinh not
- }
- 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