# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
541007 | 2022-03-22T06:21:25 Z | Kiarat | Money (IZhO17_money) | C++14 | 0 ms | 212 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector <pair<ll,ll>> v; int main(){ ll n; cin >> n; ll a[n+1]; for(int i=1;i<=n;i++) { cin >> a[i]; } a[n+1] = -10; ll ans=0; ll sum=0; ll cnt=0,ss=100000; for(ll i=2;i<=n+1;i++){ if(a[i-1] <= a[i]){ ss = min(a[i-1],ss); cnt = max(a[i],cnt); } else{ v.push_back({ss,cnt}); cnt=0,ss=100000; sum++; } } sort(v.begin(),v.end()); for(int i=1;i<v.size();i++){ if(v[i].first >= v[i-1].first && v[i].second <= v[i-1].second){ continue; } else if(v[i].first >= v[i-1].first && v[i].first >= v[i-1].second ){ continue; } else if(v[i-1].second <= v[i].first && v[i-1].second <= v[i].second){ continue; } else{ sum++; } } if(sum == 1){ cout << 0 ; } else cout << sum; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Incorrect | 0 ms | 212 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |