1
Problem on 2nd test of "Kefa and First Steps"
source link: http://codeforces.com/blog/entry/99014
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
I write 3, 2, 2, 9, and I get 3 from my compiler. But in the second test on Codeforces, it gets 0. I can't understand why.
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, ans = 1;
scanf("%d", &n);
int a[n];
vector <int> s;
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
}
for(int i = 0; i <= n - 1; i++){
if(a[i] <= a[i + 1]){
ans++;
}
else{
s.push_back(ans);
ans = 1;
}
}
int size = s.size();
int mx = 0;
for(int i = 0; i < size; i++){
if(s[i] >= mx){
mx = s[i];
}
}
cout << mx;
return 0;
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK