Submission #166901

#TimeUsernameProblemLanguageResultExecution timeMemory
166901apostoldaniel854Money (IZhO17_money)C++14
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define dbg(x) cerr << #x << " " << x << "\n" const int N = 1e6; int a[1 + N], pos[1 + N]; int in_use[1 + N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; pos[a[i]] = i; } int ans = 0; priority_queue <int> pq; for (int i = 1; i <= n; i++) { if (pq.size () && -pq.top () == i) pq.pop (); else ans++; int x = pos[i]; in_use[x] = true; if (x + 1 <= n && !in_use[x + 1]) pq.push (-a[x + 1]); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...