94062024-02-21 13:11:46csaron71Szigetek (35 pont)cpp17Accepted 35/3527ms6088 KiB
#include <bits/stdc++.h>
using namespace std;



int main() {
	int n;
	cin >> n;
	vector<int> szigetek(n);
	for (int i=0; i<n; i++) {
		cin >> szigetek[i];
	}

	vector<int> dp(n, 0);
	dp[n-1]=szigetek[n-1];
	dp[n-2]=szigetek[n-1]+szigetek[n-2];
	dp[n-3]=szigetek[n-1]+szigetek[n-3];
	for (int i=n-4; i>=0; i--) {
		dp[i]=min(dp[i+1], dp[i+2])+szigetek[i];
	}
	cout << dp[0];
}
SubtaskSumTestVerdictTimeMemory
base35/35
1Accepted0/03ms1812 KiB
2Accepted0/027ms3408 KiB
3Accepted1/13ms2264 KiB
4Accepted1/13ms2464 KiB
5Accepted1/13ms2636 KiB
6Accepted1/13ms2728 KiB
7Accepted1/13ms2856 KiB
8Accepted2/23ms3068 KiB
9Accepted2/23ms3192 KiB
10Accepted2/23ms3400 KiB
11Accepted2/24ms3620 KiB
12Accepted2/24ms3972 KiB
13Accepted2/24ms4236 KiB
14Accepted2/27ms4372 KiB
15Accepted2/29ms4712 KiB
16Accepted2/214ms5140 KiB
17Accepted2/219ms5360 KiB
18Accepted2/221ms5752 KiB
19Accepted2/224ms5860 KiB
20Accepted2/225ms5748 KiB
21Accepted2/227ms6000 KiB
22Accepted2/227ms6088 KiB