P16353 「Diligent-OI R3 A」说好不哭题解
题面:
小 C 想知道,是否存在一个长度为 的整数序列满足最大非空子段和为 ,最小非空子段和为 。
若存在,输出 YES,否则输出 NO。
请注意,若序列 可以通过将序列 分别在前面和后面删除若干个元素(可以为 个)得到,则定义 是 的子段。
思路:
喜欢不开 long long 的人有福了
考虑多种情况
-
的情况,这种情况只有 才可以
-
的情况,只要 就可以,反之则不行
-
且不符合情况2的情况下,只要满足 就可以 ,反之则不行
-
不符合以上情况的其他情况均可
思路有了,代码就很简单了:
code:
#include<iostream>
#define ll long long
using namespace std;
ll t,n,x,y;
bool judge(){
if(y > 0){
if(x >= n * y)return true;
else return false;
}
else if(x < 0){
if(y <= n * x)return true;
else return false;
}
else{
return true;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cin.tie(0);
cin>>t;
for(int i = 1;i <= t; i ++){
cin>>n>>x>>y;
if(n==1){
if(x == y)cout<<"YES\n";
else cout<<"NO\n";
continue;
}
if(judge() == false){
cout<<"NO\n";
}
else{
cout<<"YES\n";
}
}
return 0;
}