1341A - Nastya and Rice - CodeForces Solution


math *900

Please click on ads to support us..

Python Code:

from sys import dllhandle


t = int(input())
for p in range(1, t+1):
    inf = list(map(int, input().split()))
    n = inf[0]
    a = inf[1]
    b = inf[2]
    c = inf[3]
    d = inf[4]
    Max=n*(a+b)
    Min=n*(a-b)
    if Max<c-d or Min>c+d:
        print("No")
    else:
        print("Yes")

C++ Code:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll mod=1e9+7;
long double fact(int N){
    if(N < 0) 
        return 0; 
    if (N == 0)
        return 1; 
    else 
        return N * fact(N - 1); 
}
struct batya {
    vector <long long> tree;
    ll size;
    void init(ll n) {
        size = 1;
        while (size < n) {
            size *= 2;
        }
        tree.assign(2 * size - 1, 0);
    }
 
    void set(int i, int v, int x, int lx, int rx) {
        if (rx - lx == 1) {
            tree[x] = v;
            return;
        }
        int m = (lx + rx) / 2;
        if (i < m) {
            set(i, v, 2 * x + 1, lx, m);
        }
        else {
            set(i, v, 2 * x + 2, m, rx);
        }
        tree[x] =min(tree[2 * x + 1],tree[2 * x + 2]);
    }
 
    void set(int i, int v) {
        set(i, v, 0, 0, size);
    }
    ll sum(int l, int r, int x, int lx, int rx){
        if (lx >= r || rx <= l) {
            return 1000000000;
        }
        if (lx >= l && rx <= r) {
            return tree[x];
        }
        int m = (lx + rx) / 2;
        long long s1 = sum(l, r, 2 * x + 1, lx, m);
        long long s2 = sum(l, r, 2 * x + 2, m, rx);
        return min(s1,s2);
    }
 
    ll sum(int l, int r) {
       return sum(l, r, 0, 0, size);
    }
};
/* void upd (int pos, int v = 1, int tl = 1, int tr = N) {
 	if (tl == tr) {
 		t[v]++;
 		return;
 	}
 	int tm = tl + tr >> 1;
	if (pos <= tm) upd(pos, v << 1, tl, tm);
	else upd(pos, v << 1 | 1, tm + 1, tr);
	t[v] = t[v << 1] + t[v << 1 | 1];
}
 
int get (int l, int r, int v = 1, int tl = 1, int tr = N) {
	if (tl > r || tr < l) return 0; 
	if (tl >= l && tr <= r) return t[v];
	int tm = tl + tr >> 1;
	int a = get(l, r, v << 1, tl, tm);
	int b = get(l, r, v << 1 | 1, tm + 1, tr);
	return (a + b);
}*/
string as(ll x){
    string ans;
    while(x>0){
        ans+=((x%2)+'0');
        x/=2;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
   cout.tie(0);
    ll t;
    cin>>t;
    while(t--){
        ll n,a,b,c,d;
        cin>>n>>a>>b>>c>>d;
        if((a+b)*n<c-d){ 
            cout<<"No"<<endl;
            continue;
        }
        else if((c+d)<(a-b)*n){
            cout<<"No"<<endl;
            continue;
        }
        else cout<<"Yes"<<endl;
    }
return 0;
}


Comments

Submit
0 Comments
More Questions

17A - Noldbach problem
1350A - Orac and Factors
1373A - Donut Shops
26A - Almost Prime
1656E - Equal Tree Sums
1656B - Subtract Operation
1656A - Good Pairs
1367A - Short Substrings
87A - Trains
664A - Complicated GCD
1635D - Infinite Set
1462A - Favorite Sequence
1445B - Elimination
1656C - Make Equal With Mod
567A - Lineland Mail
1553A - Digits Sum
1359B - New Theatre Square
766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table