제출 #1272835

#제출 시각아이디문제언어결과실행 시간메모리
1272835soabAirplane (NOI23_airplane)C++20
0 / 100
45 ms12944 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 = 1; i <= l; i++) { a[i] = max(a[i], a[i - 1]); } for(int i = l; i <= r; i++) { a[i] = maxn; } for(int i = n - 1; i > r; i--) { a[i] = max(a[i], a[i + 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...