Skip to content

Commit

Permalink
[Silver III] Title: 주유소, Time: 20 ms, Memory: 2804 KB, Score: 100 poi…
Browse files Browse the repository at this point in the history
…nt -BaekjoonHub
  • Loading branch information
belowyoon committed Feb 23, 2024
1 parent deeb321 commit 005742d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions 백준/Silver/13305. 주유소/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

### 성능 요약

메모리: 3196 KB, 시간: 12 ms
메모리: 2804 KB, 시간: 20 ms

### 분류

그리디 알고리즘

### 제출 일자

2024년 2월 23일 18:07:04
2024년 2월 23일 18:21:30

### 문제 설명

Expand Down
15 changes: 9 additions & 6 deletions 백준/Silver/13305. 주유소/주유소.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

int main()
Expand All @@ -11,22 +12,24 @@ int main()
int n;
vector<int> road;
vector<int> costs;
vector<int> dp;
cin >> n;
road.assign(n, 0);
costs.assign(n, 0);
dp.assign(n, 0);

long long total = 0;
for (int i = 0; i < n - 1; i++) {
cin >> road[i];
}
for (int i = 0; i < n; i++) {
cin >> costs[i];
}
int minCost = 1000000001;
long long minCost = 1000000001;
for (int i = 1; i < n; i++) {
minCost = min(costs[i-1], minCost);
dp[i] = dp[i-1] + (minCost * road[i-1]);
if (minCost > costs[i-1]) {
minCost = costs[i-1];
}
total += minCost * road[i-1];
}
cout << dp[n-1];
cout << total;
return 0;
}

0 comments on commit 005742d

Please sign in to comment.