Submission #307016

# Submission time Handle Problem Language Result Execution time Memory
307016 2020-09-26T18:47:32 Z NintsiChkhaidze Exercise Deadlines (CCO20_day1problem2) C++14
0 / 25
1000 ms 384 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long
using namespace std;
int a[200005],b[200005];
int main(){
    int n;
    cin>>n;
    for (int i = 1; i <= n; i++)
        cin>>a[i],b[i] = a[i];
    sort(b + 1,b + n + 1);
    for (int i = 1;i <= n; i++)
        if (b[i] < i) {
            cout<<-1;
            return 0;
        }
    int ans=0;
    while (true){
        int ind = 0;
        for (int i = n; i >= 1; i--)
            if (a[i] < i) {ind = i; break;}
        if (ind == 0) break;
        int m = a[ind];
        for (int i = ind - 1; i >= 1; i--){
            swap(a[i],a[i + 1]);
            ans++;
            if (m >= i) break;
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -