[백준] 13305번: 주유소
2021. 2. 14. 14:09ㆍAlgorithm/백준
13305번: 주유소
표준 입력으로 다음 정보가 주어진다. 첫 번째 줄에는 도시의 개수를 나타내는 정수 N(2 ≤ N ≤ 100,000)이 주어진다. 다음 줄에는 인접한 두 도시를 연결하는 도로의 길이가 제일 왼쪽 도로부터 N-1
www.acmicpc.net
#include<iostream>
#include<vector>
using namespace std;
long long solution(vector<long long>&dist, vector<long long>&cost) {
long long total = 0; int idx = 0;
total += cost[0] * dist[1];
for (int i = 1;i < dist.size() - 1;i++) {
if (cost[i] < cost[idx]) {
total += cost[i] * dist[i + 1];
idx = i;
}
else total += cost[idx] * dist[i + 1];
}
return total;
}
int main() {
int n;
cin >> n;
vector<long long>dist(n, 0);
vector<long long>cost(n, 0);
for (int i =1;i < n ;i++) {
cin >> dist[i];
}
for (int i = 0;i < n;i++) {
cin >> cost[i];
}
cout<<solution(dist, cost);
}
'Algorithm > 백준' 카테고리의 다른 글
[백준] 2156번: 포도주 시식 (0) | 2021.02.15 |
---|---|
[백준] 17086번: 아기 상어2 (0) | 2021.02.15 |
[백준] 1298번: 노트북의 주인을 찾아서 (0) | 2021.02.13 |
[백준] 2188번: 축사 배정 (0) | 2021.02.13 |
[백준]9576번 : 책 나눠주기 (0) | 2021.02.13 |