Skip to content

Conversation

@flydongwoo
Copy link
Collaborator

@flydongwoo flydongwoo commented Aug 27, 2025

πŸ”— 문제 링크

https://www.acmicpc.net/problem/11399

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

20λΆ„

✨ μˆ˜λ„ μ½”λ“œ

μ•ˆλ…•ν•˜μ‹­λ‹ˆκΉŒ!
μ œκ°€ κ·Έλ™μ•ˆ νœ΄κ°€μ™€ λ°€λ¦° μ‚¬μ΄λ“œ ν”„λ‘œμ νŠΈ 마감 κΈ°ν•œμ΄ λ‹€κ°€μ™€μ„œ PR이 λœΈν–ˆλ„€μš” μ£„μ†‘ν•©λ‹ˆλ‹€
μ•žμœΌλ‘œ κ°œκ°•ν›„μ—λŠ” 밀리지 μ•Šκ²Œ μ΅œλŒ€ν•œ μ—΄μ‹¬νžˆ ν•˜λ„λ‘ λ…Έλ ₯ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€!!!

이번 λ¬Έμ œλŠ” νœ΄κ°€μ™€ λ―ΈνŒ…μœΌλ‘œ 인해 λˆμ„ 많이 μ¨μ„œ ATM이 κ°„μ ˆν•΄μ§„ @flydongwoo λ₯Ό μœ„ν•΄ μ€€λΉ„ν•œ λ¬Έμ œμž…λ‹ˆλ‹€.
이 λ¬Έμ œλŠ” μ•ž μ‚¬λžŒ μ‹œκ°„μ΄ μ§§μ„μˆ˜λ‘ 전체 합이 μž‘μ•„μ§„λ‹€λŠ” 것을 νŒŒμ•…ν•˜λ©΄ μ‰½κ²Œ ν’€ 수 μžˆλŠ” λ¬Έμ œμž…λ‹ˆλ‹€!

μ‚¬λžŒ 수λ₯Ό μž…λ ₯λ°›κ³ 
μ‚¬λžŒ 수만큼 각 μ‚¬λžŒλ³„λ‘œ κ±Έλ¦¬λŠ” μ‹œκ°„μ„ vector line에 μž…λ ₯λ°›κ³ 
line을 μ˜€λ¦„μ°¨μˆœ μ •λ ¬ν•œ λ’€
n번 λ°˜λ³΅ν•˜λ©° i번째 μ‚¬λžŒμ΄ κ±Έλ¦¬λŠ” μ‹œκ°„μ΄ (n-i)번 만큼 ν•©μ‚°λœλ‹€κ³  κ³„μ‚°ν•œ 것.

μ „ν˜•μ μΈ 그리디λ₯Ό μ—°μŠ΅ν•  수 μžˆλŠ” λ¬Έμ œμ˜€μŠ΅λ‹ˆλ‹€!

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	vector<int>line;

	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		line.push_back(k);
	}
	sort(line.begin(), line.end());

	int answer = 0;
	for (int i = 0; i < n; i++) {
		answer += line[i] * (n - i);
	}
	cout << answer;
}

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

Just do it!
μƒκ°ν•˜λŠ”λŒ€λ‘œ ν’€λ©΄ λœλ‹€! μ΅œμ„ μ˜ 값을 μ°ΎλŠ” 말 κ·ΈλŒ€λ‘œ 그리디 μ•Œκ³ λ¦¬μ¦˜!

Copy link
Collaborator

@Seol-Munhyeok Seol-Munhyeok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

운영체제 μ‹œκ°„μ— λ•Œλ¬Έ μŠ€μΌ€μ€„λ§μ΄ λ– μ˜¬λžλ„€μš”. μ‹€ν–‰μ‹œκ°„μ΄ 짧은 ν”„λ‘œμ„ΈμŠ€λΆ€ν„° μš°μ„ μˆœμœ„λ‘œ μ²˜λ¦¬ν•˜λŠ” Shortest Job First (SJF) μŠ€μΌ€μ€„λ§μ΄ κ°€μž₯ 졜적의 λŒ€κΈ° μ‹œκ°„μ„ μ œκ³΅ν•œλ‹€λŠ” 점을 μ•Œκ³  있으면 μ‰½κ²Œ ν’€ 수 μžˆλŠ” λ¬Έμ œμ˜€μŠ΅λ‹ˆλ‹€.

λ”°λΌμ„œ μ‹œκ°„μ„ μ˜€λ¦„μ°¨μˆœμœΌλ‘œ μ •λ ¬ν•œ λ’€, λˆ„μ ν•© 배열을 κ΅¬ν•œ λ’€, κ·Έ λˆ„μ ν•© 배열에 μžˆλŠ” λͺ¨λ“  μ›μ†Œμ˜ 합을 κ΅¬ν•˜λŠ” μ‹μœΌλ‘œ ν’€μ—ˆμŠ΅λ‹ˆλ‹€.

n = int(input())
lst = list(map(int, input().split()))

lst.sort()
p_sum = [0] * (n + 1)

for i in range(n):
    p_sum[i + 1] = p_sum[i] + lst[i]

print(sum(p_sum))

μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€!

@hyeokbini
Copy link
Collaborator

μ•žμͺ½μ— μ„œ μžˆλŠ” μ‚¬λžŒμ€ 더 많이 합에 μ μš©λ˜λ―€λ‘œ, μ•žμͺ½μ— 더 적은 μ‹œκ°„μ„ μ‚¬μš©ν•˜λŠ” 인원을 λ°°μΉ˜ν•΄μ•Ό ν•œλ‹€λŠ” μ•„μ΄λ””μ–΄λ§Œ μžˆλ‹€λ©΄ κ°„λ‹¨νžˆ κ΅¬ν˜„ν•  수 μžˆλŠ” λ¬Έμ œμ˜€μŠ΅λ‹ˆλ‹€. 문제 ν‘Έμ‹œλŠλΌ κ³ μƒν•˜μ…¨μ–΄μš”!

ATM / c++
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //freopen("test.txt", "rt", stdin);
    int n, ans = 0;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    for(int i = n; i > 0; i--)
    {
        ans += arr[n - i] * i;
    }
    cout << ans;
    return 0;
}

@mj010504
Copy link
Collaborator

mj010504 commented Sep 8, 2025

저도 κ°„λ‹¨ν•˜κ²Œ 인원을 적은 μ‹œκ°„μ„ μ‚¬μš©ν•˜λŠ” μͺ½μœΌλ‘œ μ •λ ¬ν•˜μ—¬ ν•΄κ²°ν–ˆμŠ΅λ‹ˆλ‹€.
μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€.

#include <bits/stdc++.h>

using namespace std;

int main() {
   // freopen("input.txt", "rt", stdin);  
    int n; cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    vector<int> sv(n);
    sv[0] = v[0];
    for(int i = 1; i < n; i++) sv[i] = v[i] + sv[i-1];
    int res = 0;
    for(int i = 0; i < n; i++) {
        res += sv[i];
    }

    cout << res;

   
    return 0;
}

@flydongwoo flydongwoo merged commit 3bc6938 into main Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants