NC230837. Kobolds and Catacomb
描述
输入描述
The first line of the input contains a single integer , denoting the number of kobolds.
The second line contains integers , representing the heights of the kobolds in the queue.
输出描述
Print a single integer, denoting the maximum number of groups.
示例1
输入:
5 1 3 2 7 4
输出:
3
C++ 解法, 执行用时: 469ms, 内存消耗: 8236K, 提交时间: 2021-11-24 10:08:25
#include<bits/stdc++.h> using namespace std; const int N=1e6+10; int n,a[N],mn=1e9,mx=0,b[N],ans; int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=n;i>=1;i--){ b[i]=mn; mn=min(mn,a[i]); } for(int i=1;i<=n;i++){ mx=max(mx,a[i]); if(mx<=b[i]) ans++; } cout<<ans<<"\n"; }
pypy3 解法, 执行用时: 1126ms, 内存消耗: 150412K, 提交时间: 2021-11-23 21:31:19
n = int(input()) a = list(map(int, input().split())) b = [x for x in a] sumA = 0 sumB = 0 b.sort() cnt = 0 for i in range(n): sumA += a[i] sumB += b[i] if sumA == sumB: cnt += 1 print(cnt)
Python3 解法, 执行用时: 1520ms, 内存消耗: 123908K, 提交时间: 2021-11-20 20:27:57
n = int(input()) a = list(map(int,input().split())) b = a[::] s1 = 0; s2 = 0; b.sort() ans = 0 for i in range(n): s1 += a[i] s2 += b[i] ans += 1 if s1 == s2 else 0 print(ans)