issues
search
2024-TEAM-05
/
algorithm-for-kakao
μΉ΄μΉ΄μ€ κΈ°μΆ λ¬Έμ κ°μ¦μπ£
0
stars
0
forks
source link
[λ°±μ€] νλ°°
#48
Open
hye-on
opened
1 month ago
hye-on
commented
1 month ago
π
νλ°°
uijin-j
commented
3 weeks ago
π λκΈ ν νλ¦Ώ
Language : Java
μ±λ₯
μ½λ νμ΄
```java import java.io.*; import java.util.*; /** * 14:32 μμ! */ public class Main { /* * 그리λ * 1 2 10 : 1λ²μμ +10 * 1 3 20 : 1-2λ²μμ +20 * 2 3 10 : 2λ²μμ +10 * 1 4 30 : 1-3λ²μμ +10 * 2 4 20 * 3 4 20 : 3λ²μμ +20 */ public static void main(String[] args) throws Exception { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(bf.readLine()); int n = Integer.parseInt(st.nextToken()); int c = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(bf.readLine()); int[][] info = new int[m][3]; for(int i = 0; i < m; ++i) { st = new StringTokenizer(bf.readLine()); info[i][0] = Integer.parseInt(st.nextToken()); info[i][1] = Integer.parseInt(st.nextToken()); info[i][2] = Integer.parseInt(st.nextToken()); } Arrays.sort(info, (a, b) -> a[1] - b[1] == 0 ? a[0] - b[0] : a[1] - b[1]); int[] remain = new int[n+1]; Arrays.fill(remain, c); int count = 0; for(int i = 0; i < m; ++i) { int from = info[i][0]; int to = info[i][1]; int cnt = info[i][2]; for(int j = from; j < to; ++j) { cnt = Math.min(cnt, remain[j]); } if(cnt == 0) continue; for(int j = from; j < to; ++j) { remain[j] -= cnt; } count += cnt; } System.out.println(count); } } ```
μ½λ©νΈ
- μ²μμλ 보λ΄λ λ§μ κΈ°μ€μΌλ‘ μ λ ¬μ μκ°ν΄μ 그리λ λ¬Έμ κ° μλ μ€ μμλ€μπ’ μκ³ λ³΄λ λμ°©νλ λ§μμ κΈ°μ€μΌλ‘ μ λ ¬νκ³ (μ΅λν 빨리 λ΄λ €μ€μΌ λ€μ λ λ΄λ €μ€ μ μκΈ° λλ¬Έ) 그리λλ‘ νλ©΄ λλ λ¬Έμ μμ΅λλ€!
hye-on
commented
3 weeks ago
π λκΈ ν νλ¦Ώ
Language : C++
μ±λ₯
μ½λ νμ΄
```cpp #include
#include
#include
#include
using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, c, m; cin >> n >> c >> m; vector
> v(m); // {λμ°©, μμ, λ°μ€} for (int i = 0; i < m; i++) { int start, end, box; cin >> start >> end >> box; v[i] = { end, start, box }; // λμ°©μ§ κΈ°μ€ μ λ ¬μ μν΄ endλ₯Ό 첫λ²μ§Έλ‘ } sort(v.begin(), v.end()); // κΈ°λ³Έ μ λ ¬λ§μΌλ‘ λμ°©μ§, μμμ§ μ μ λ ¬λ¨ vector
capacity(n + 1, c); int ans = 0; for (int i = 0; i < m; i++) { int end = get<0>(v[i]); int start = get<1>(v[i]); int box = get<2>(v[i]); int possible = c; for (int j = start; j < end; j++) { possible = min(possible, capacity[j]); } int mBox = min(possible, box); for (int j = start; j < end; j++) { capacity[j] -= mBox; } ans += mBox; } cout << ans << '\n'; return 0; } ```
μ½λ©νΈ
- μΆλ°νλ λμλ₯Ό κΈ°μ€μΌλ‘ μ λ ¬νκ³ λμ°©νλ μ κ° λ λΉ λ₯Έ κ²μ΄ λ±μ₯ν κ²½μ° κ΅μ²΄νλ κ²μΌλ‘ νμλλ° νλ¦° μ£μ§ μΌμ΄μ€κ° κ³μ μμλ κ² κ°μ΅λλ€ γ λμ°©νλ λμ κΈ°μ€μΌλ‘ μ λ Ών΄μ νμ΄μΌνλ€μ
π νλ°°