답안 #643098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643098 2022-09-21T08:14:59 Z TimDee Climbers (RMI18_climbers) C++17
0 / 100
3 ms 356 KB
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i=0; i<n; ++i)

void solve() {

	int n; cin>>n;
	vector<int> a(n); forn(i,n) cin>>a[i];
	int ans=0;
	int l=0,r=n-1;
	int h=0;
	while (l<r) {
		if (a[l+1]>=h) {
			if (a[r-1]>=h) {
				if (a[l+1]<a[r-1]) {
					ans+=a[l+1]-h;
					h=a[l+1];
					++l;
				} else if (a[l+1]>a[r-1]) {
					ans+=a[r-1]-h;
					h=a[r-1];
					--r;
				} else {
					ans+=a[l+1]-h;
					h=a[l+1];
					++l, --r;
				}
			} else {
				if (a[l]<a[r-1]) {
					ans+=h-a[r-1];
					h=a[r-1];
					--r;
				} else if (a[l]>a[r-1]) {
					ans+=h-a[l];
					h=a[l];
					if ((l==0) || a[l-1]>a[l]) {
						cout<<"NO\n";
						return;
					} else --l;
				} else {
					ans+=h-a[l];
					h=a[l];
					--r;
				}
			}
		} else {
			if (a[r-1]<h) {
				if (a[l+1]>a[r-1]) {
					ans+=h-a[l+1];
					h=a[l+1];
					++l;
				} else if (a[l+1]<a[r-1]) {
					ans+=h-a[r-1];
					h=a[r-1];
					--r;
				} else {
					ans+=h-a[l+1];
					h=a[l+1];
					++l,--r;
				}
			} else {
				if (a[r]<a[l+1]) {
					ans+=h-a[l+1];
					h=a[l+1];
					++l;
				} else if (a[r]>a[l+1]) {
					ans+=h-a[r];
					h=a[r];
					if ((r==n-1) || a[r+1]>a[r]) {
						cout<<"NO\n";
						return;
					} else ++r;
				} else {
					ans+=h-a[r];
					h=a[r];
					++l;
				}
			}
		}
		//cout<<l<<' '<<r<<' '<<ans<<' '<<h<<'\n';
	}
	cout<<ans;
}

int32_t main() {
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 1 ms 304 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 2 ms 312 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 300 KB Output isn't correct
2 Incorrect 0 ms 300 KB Output isn't correct
3 Incorrect 1 ms 304 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Incorrect 2 ms 312 KB Output isn't correct
7 Incorrect 2 ms 340 KB Output isn't correct
8 Incorrect 2 ms 340 KB Output isn't correct
9 Incorrect 2 ms 340 KB Output isn't correct
10 Incorrect 3 ms 356 KB Output isn't correct