Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

43-pknujsp #176

Merged
merged 7 commits into from
May 3, 2024
Merged

43-pknujsp #176

merged 7 commits into from
May 3, 2024

Conversation

pknujsp
Copy link
Collaborator

@pknujsp pknujsp commented Apr 2, 2024

πŸ”— 문제 링크

μ €μšΈ

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

40λΆ„

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

주어진 좔듀을 μ‘°ν•©ν–ˆμ„λ•Œ 잴 수 μ—†λŠ” 무게의 μ΅œμ†Ÿκ°’μ„ μ°ΎκΈ°

  • x : 잴 수 μžˆλŠ” 무게의 μ΅œλŒ“κ°’, 0으둜 μ΄ˆκΈ°ν™”
  • weights : μΆ”μ˜ 무게 리슀트

1. weights μ˜€λ¦„μ°¨μˆœ μ •λ ¬

  • μž‘μ€ λ¬΄κ²ŒλΆ€ν„° λ”ν•˜λ©΄μ„œ 잴 수 μžˆλŠ” 무게의 λ²”μœ„λ₯Ό μ¦κ°€μ‹œν‚€κΈ° μœ„ν•΄μ„œ μ •λ ¬ν•œλ‹€
  • 정렬을 ν†΅ν•΄μ„œ μΆ”μ˜ 무게λ₯Ό μˆœνšŒν•  λ–„λ§ˆλ‹€ x + 1이 ν˜„μž¬ λΉ„κ΅ν•˜λŠ” μΆ”μ˜ λ¬΄κ²Œλ³΄λ‹€ μž‘κ±°λ‚˜ 같은지 확인 κ°€λŠ₯

2. μž‘μ€ 것 λΆ€ν„° μˆœμ„œλŒ€λ‘œ μΆ”λ₯Ό μˆœνšŒν•˜λ©΄μ„œ 잴 수 μ—†λŠ” 무게λ₯Ό 확인해본닀

  • x + 1의 값이 ν˜„μž¬ μΆ”μ˜ λ¬΄κ²Œλ³΄λ‹€ μž‘λ‹€λ©΄, 이 λ¬΄κ²ŒλŠ” 츑정이 λΆˆκ°€λŠ₯ν•˜λ‹€
    • μ§μ „κΉŒμ§€ ν™•μΈν–ˆλ˜ λͺ¨λ“  μΆ”λ“€μ˜ μ‘°ν•©μœΌλ‘œ xκΉŒμ§€λŠ” 무게λ₯Ό 잴 수 μžˆμ§€λ§Œ
    • x + 1은 잴 수 μ—†μŒ
    • 반볡 μ’…λ£Œ
  • 그렇지 μ•Šλ‹€λ©΄ x에 ν˜„μž¬ μΆ”μ˜ 무게λ₯Ό λ”ν•˜μ—¬ μ¦κ°€μ‹œν‚¨λ‹€

μ˜ˆμ‹œ : [3, 1, 6, 2, 7, 30, 1] -> [1, 1, 2, 3, 6, 7, 30]

ν˜„μž¬ μΆ”μ˜ 무게 x x + 1 x + ν˜„μž¬ μΆ”μ˜ 무게 μΈ‘μ • κ°€λŠ₯ μ—¬λΆ€
1 0 1 1 O
1 1 2 2 O
2 2 3 4 O
3 4 5 7 O
6 7 8 13 O
7 13 14 20 O
30 20 21 X

3. x + 1 좜λ ₯ : μ΅œμ†Œ 무게

πŸ”’ μ½”λ“œ

N = int(input())
weights = list(map(int, input().split()))
weights.sort()

x = 0
for weight in weights:
    # x + 1이 ν˜„μž¬ μΆ”μ˜ λ¬΄κ²Œλ³΄λ‹€ μž‘λ‹€λ©΄, 츑정이 λΆˆκ°€λŠ₯함
    if x + 1 < weight:
        break

    x += weight

print(x + 1)

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

@tgyuuAn
Copy link
Member

tgyuuAn commented Apr 4, 2024

import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())
weights = sorted(list(map(int, input().split())))

temp = 0
for idx, weight in enumerate(weights):    
    if weight > temp+1: 
        temp += 1
        break

    else: temp += weight
else:
    temp += 1
    
print(temp)

μ•„... 이 문제 동아리 λ°©μ—μ„œ 5λͺ…(@yuyu0830 , @gjsk132 , @9kyo-hwang , @LightningXQ) μ—μ„œ 똘똘 λ­‰μ³μ„œ λ‘œμ§μ„ 생각해내긴 ν–ˆλŠλ°,,,

μ˜ˆμ™Έ μ²˜λ¦¬μ—μ„œ μ‹œκ°„μ„ μ—„μ²­ 많이 μ»λ„€μš”...







μ€€μ„±λ‹˜ μ½”λ“œ λ„ˆλ¬΄ μ§§μ•„μ„œ λ†€λž¬μ–΄μš” ...

배우고 κ°‘λ‹ˆλ‹€...

@yuyu0830
Copy link

yuyu0830 commented Apr 6, 2024

#include <iostream>
#include <queue>

using namespace std;

int main() {
    priority_queue<int, vector<int>, greater<int> > q;
    int n; cin >> n;
    
    for (int i = 0; i < n; i++) {
        int t; cin >> t;
        q.push(t);
    }

    bool first = true;
    int max = 1;

    while (!q.empty()) {
        int t = q.top();
        q.pop();

        if (first && t != 1) 
            break;

        first = false;
        
        if (t <= max) max += t;
        else break;
    }

    printf("%d\n", max);
}

μ–΄... x <= max κ°€ μ•„λ‹ˆλΌ x + 1 < max μ΄λ ‡κ²Œ λΉ„κ΅ν•˜λ©΄ 처음 비ꡐ μ˜ˆμ™Έ μ²˜λ¦¬λ„ ν•„μš”κ°€ μ—†κ΅°μš”..? μ–Όλ§ˆ 전에 ν‘Ό 문제인데 ν•œ 수 배우고 κ°‘λ‹ˆλ‹€...

@MunbinLee MunbinLee merged commit b59cef7 into main May 3, 2024
1 check passed
@MunbinLee MunbinLee deleted the 43-pknujsp branch May 3, 2024 15:38
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.

4 participants