Submission #1279452

#TimeUsernameProblemLanguageResultExecution timeMemory
1279452ghammazhassanAirplane (NOI23_airplane)C++20
0 / 100
31 ms1856 KiB
// #include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <set>
#include <deque>
using namespace std;
#define int long long
#define endl "\n"
#define fi first
#define se second
const int M=998244353;
const int inf = 1e14;
const int LOG=20;
const int N=3e5+5;
int n , m , c , w , k , t=1 , q=1 , x , y , z , l , r;
void solve()
{   
    cin >> n >> m;
    vector<int>a(n);
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    for (int i=0;i<m;i++){
        cin >> x >> y;
    }
    if (n==1){
        cout << 0 << endl;
        return;
    }
    c=0;
    int h=0;
    for (int i=1;i<n;i++){
        c+=max(a[i]-h,1ll);
        h=max(h,a[i]);
    }
    int f=0;
    for (int i=n-1;i>0;i--){
        a[i-1]=max(a[i],a[i-1]);
        if (a[i]==h){
            f=i;
            break;
        }
    }
    for (int i=f;i<n;i++){
        if (a[i]<h)h--;
    }
    cout << c+h << endl;
    
}
signed main()    
{

    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);//DO NOT USE IN INTERACTIVE
    cout << fixed << setprecision(9);
    srand(time(0));
    // int t=1;
    // cin >> t;
    for (int _=1;_<=t;_++){
        solve();
        q++;
    }
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...