Submission #27828094


Source Code Expand

#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
map<string, int>t;
#define int long long
int dp[61][2];
int val[61][2];
int arr[61];

signed main()
{
	int N,Q;
	cin >> N>>Q;
	int i;
	for (i = 0; i < N; i++)
	{
		cin >> arr[i];
	}
	for (i = N - 1; i >= 0; i--)
	{
		int p = Q / arr[i];
		val[i][0] = Q - p * arr[i];
		val[i][1]= val[i][0] - arr[i];
		if (i == N - 1)
		{
			dp[i][1] = p + 1;
			dp[i][0] = p;
		}
		else
		{
			dp[i][1] = min(dp[i + 1][1] + abs(val[i][1] - val[i + 1][1]) / arr[i], dp[i + 1][0] + abs(val[i][1] - val[i + 1][0]) / arr[i]);
			dp[i][0] = min(dp[i + 1][1] + abs(val[i][0] - val[i + 1][1]) / arr[i], dp[i + 1][0] + abs(val[i][0] - val[i + 1][0]) / arr[i]);
		}
	}
	cout << dp[0][0];
}

Submission Info

Submission Time
Task E - Minimal payments
User codingmorning
Language C++ (GCC 9.2.1)
Score 500
Code Size 815 Byte
Status AC
Exec Time 7 ms
Memory 3632 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 34
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 7 ms 3588 KiB
hand_02.txt AC 2 ms 3516 KiB
hand_03.txt AC 2 ms 3516 KiB
hand_04.txt AC 2 ms 3588 KiB
random_01.txt AC 2 ms 3400 KiB
random_02.txt AC 2 ms 3440 KiB
random_03.txt AC 2 ms 3588 KiB
random_04.txt AC 2 ms 3444 KiB
random_05.txt AC 1 ms 3580 KiB
random_06.txt AC 2 ms 3404 KiB
random_07.txt AC 3 ms 3432 KiB
random_08.txt AC 2 ms 3428 KiB
random_09.txt AC 2 ms 3544 KiB
random_10.txt AC 3 ms 3564 KiB
random_11.txt AC 2 ms 3632 KiB
random_12.txt AC 2 ms 3620 KiB
random_13.txt AC 2 ms 3432 KiB
random_14.txt AC 2 ms 3548 KiB
random_15.txt AC 3 ms 3596 KiB
random_16.txt AC 2 ms 3428 KiB
random_17.txt AC 2 ms 3444 KiB
random_18.txt AC 3 ms 3388 KiB
random_19.txt AC 2 ms 3516 KiB
random_20.txt AC 2 ms 3568 KiB
random_21.txt AC 2 ms 3632 KiB
random_22.txt AC 3 ms 3516 KiB
random_23.txt AC 2 ms 3428 KiB
random_24.txt AC 2 ms 3436 KiB
random_25.txt AC 2 ms 3440 KiB
random_26.txt AC 2 ms 3388 KiB
random_27.txt AC 2 ms 3404 KiB
sample_01.txt AC 2 ms 3388 KiB
sample_02.txt AC 2 ms 3516 KiB
sample_03.txt AC 2 ms 3520 KiB