답안 #886116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886116 2023-12-11T13:25:41 Z vjudge1 Airplane (NOI23_airplane) C++17
0 / 100
124 ms 13652 KB
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
int main(){
	int n,m;cin>>n>>m;
	vector<int> val(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>val[i];
	}
	vector<vector<int>> arr(n);
	for (int i = 0; i < m; i++){
		int u,v;cin>>u>>v;
		arr[u-1].push_back(v-1);
		arr[v-1].push_back(u-1);
	}
	vector<int> dp1(n);
	vector<int> dp2(n);
	int crmax = 0;
	int crans = 0;
	int ans = INF;
	for (int i = 1; i < n; ++i)
	{
		if (crmax>=val[i]) crans++;
		else crans+=val[i]-crmax;
		dp1[i]=crans;
		crmax=max(crmax,val[i]);
	}
	ans=crans+crmax;
	crmax=0;
	crans=0;
	for (int i = n-2; i >= 0; --i){
		if (crmax>=val[i]) crans++;
		else crans+=val[i]-crmax;
		dp2[i]=crans;
		crmax=max(crmax,val[i]);
	}
	ans=min(ans,crans+crmax);
	for (int i = 1; i < n-1; ++i)
	{
		ans=min(ans,dp1[i]+dp2[i]);
	}
	cout<<ans<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 124 ms 13652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 124 ms 13652 KB Output isn't correct
3 Halted 0 ms 0 KB -