[백준/BOJ]13305. 주유소 [Silver 4] (부분성공)

jychan99·2021년 9월 4일
0
post-thumbnail
  1. 주유소

문제출처 : https://www.acmicpc.net/problem/13305

code

#include <stdio.h>
int main()
{
	int i, N, index = 0, flag = 1, bridge[100000] = { 0 }, gas_station[100000] = { 0 };
	long long total = 0;
	scanf("%d", &N);
	for (i = 0; i < N - 1; i++)
		scanf("%d", &bridge[i]);
	for (i = 0; i < N; i++)
	{
		scanf("%d", &gas_station[i]);
		if (gas_station[i] != 1)
			flag = 0;
	}
	i = 1;
	if (flag == 1)
	{
		for (i = 0; i < N - 1; i++)
			total += bridge[i];
		printf("%lld", total);
	}
	else
	{
		while (1)
		{
			if (index == N)
				break;
			while (gas_station[index] <= gas_station[i])
				i++;
			for (int j = index; j < i; j++)
				total += (long long)gas_station[index] * (long long)bridge[j];
			index = i;
			i++;
		}
		printf("%lld", total);
	}
	return 0;
}

자료형도 longlong으로늘려보고, 로직도 체크해봤는데 별문제없는거 같은데 58% 정답이고 마지막 케이스가 통과가 안된다 ㅠㅠ

profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐥

0개의 댓글