제출 #1272838

#제출 시각아이디문제언어결과실행 시간메모리
1272838soabAirplane (NOI23_airplane)C++20
0 / 100
44 ms12908 KiB
// soab #include <bits/stdc++.h> using namespace std; #define int long long #define nl '\n' void io() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 2 * 1e5 + 1; int n, m, a[maxn]; vector<int> g[2 * maxn]; signed main() { io(); cin >> n >> m; for(int i = 1; i <= n; i++) { cin >> a[i]; } for(int i = 0; i < m; i++) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } int ans = 0, maxn = 0, l, r; for(int i = 1; i <= n; i++) { if(maxn < a[i]) { maxn = a[i]; l = i; } if(maxn <= a[i]) r = i; } for(int i = 2; i <= l; i++) { if(a[i - 1] > a[i]) a[i] = a[i - 1] + 1; } for(int i = l; i <= r; i++) { a[i] = maxn; } for(int i = n - 1; i > r; i--) { if(a[i + 1] > a[i]) a[i] = a[i + 1] + 1; } for(int i = 2; i <= n; i++) { if(a[i] == a[i - 1]) ans++; else ans += abs(a[i] - a[i - 1]); } cout << ans; 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...