# PROBLEM LINK:

Practice

Contest: Division 1

Contest: Division 2

Contest: Division 3

* Author:* Daanish Mahajan

*Shubham Anand Jain, Aryan*

**Testers:***Nishank Suresh*

**Editorialist:**# DIFFICULTY:

Cakewalk

# PREREQUISITES:

None

# PROBLEM:

Chef is playing NFS, and driving his car straight at U m/s. He wants to ensure that the car’s velocity is at most V m/s after S metres; and the maximum deceleration he can achieve is A m/s^2. Can he do this?

# QUICK EXPLANATION

Check if V^2 \geq U^2 - 2*A*S.

# EXPLANATION:

First, note that deceleration by A m/s^2 is the same as acceleration by -A m/s^2.

What does it mean for Chef to not be able to reach his target velocity?

It means that, even if Chef decelerates as much as possible for all S metres, his velocity at the end will be strictly greater than V m/s - and the square of his velocity will be strictly greater than V^2.

Applying the equation given in the statement, this means that V^2 < U^2 - 2*A*S.

Thus, if V^2 < U^2 - 2*A*S the answer is NO, otherwise the answer is YES.

## What about sqrt?

It is also possible to AC by checking for V < \sqrt{U^2 - 2*A*S}, but it is possible for U^2 - 2*A*S to be negative, so blindly taking the square root will likely give you a runtime error. You can instead check for V > \sqrt{max(0, U^2 - 2*A*S)}

# TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

# SOLUTIONS:

## Setter's Solution (C++)

```
#include<bits/stdc++.h>
using namespace std;
const int maxv = 1e4, minv = 1, maxt = 1e5;
int main()
{
int t; cin >> t;
int u, v, a, s;
while(t--){
cin >> u >> v >> a >> s;
string ans = "no";
if(u * u - 2 * a * s <= v * v)ans = "yes";
cout << ans << endl;
}
}
```

## Tester's Solution (C++)

```
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
int main(){
fastio;
int t;
cin>>t;
while(t--){
long long int u, v, a, s;
cin>>u>>v>>a>>s;
if(v * v >= u * u - 2 * a * s) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
```

## Editorialist's Solution (Python)

```
t = int(input())
for _ in range(t):
u, v, a, s = map(int, input().split())
if u*u - 2*a*s <= v*v:
print('Yes')
else:
print('No')
```