John likes sorting algorithms very much. He has studied quicksort, merge sort, radix sort, and many more.
A long time ago he has written a lock-free parallel string sorting program. It was a combination of burstsort and multi-key quicksort. To implement burstsort you need to build a tree of buckets. For each input string you walk through the tree and insert part of the string into the right bucket. When a bucket fills up, it "bursts" and becomes a new subtree (with new buckets).
Well, enough about the past. Today John is playing with sorting algorithms again. This time it's numbers. He has an idea for a new algorithm, "extreme sort". It's extremely fast, performance levels are OVER NINETHOUSAND. Before he tells anyone any details, he wants to make sure that it works correctly.
Your task is to help him and verify that the so-called extreme property holds after the first phase of the algorithm. The extreme property is defined as \min (x_{i,j}) \ge 0min(xi,j)≥0, where
\displaystyle x_{i,j}= \begin{cases} a_j-a_i \quad for \quad 1\le i<j\le N \\ 9001 \quad otherwise \end{cases}xi,j={aj−aifor1≤i<j≤N9001otherwise
Input Format
The first line contains a single integer NN (1 \le N \le 1024)(1≤N≤1024). The second line contains NN integers a_1 a_2 \cdot\cdot\cdot a_Na1a2⋅⋅⋅aN (1 \le a_i \le 1024)(1≤ai≤1024).
Output Format
Print one line of output containing "yes"
if the extreme property holds for the given input, "no"
otherwise.
样例输入1
2 1 2
样例输出1
yes
样例输入2
4 2 1 3 4
样例输出2
no
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
typedef pair<int,int> P;
int main(){
int a[1025];
int n;
cin>>n;
for(int i=0;i<n;i++) scanf("%d",&a[i]);
int flag=0;
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
if(a[j]<a[i]) flag=1;
}
}
if(flag){
cout<<"no";
}
else cout<<"yes";
return 0;
}
欢迎大家加入 早起学习群,一起学习一起进步!(群号:642179511)