๋ฐ์ํ
https://codeforces.com/problemset/problem/1316/A
Problem - 1316A - Codeforces
codeforces.com
์ฝ๋
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
for(int tc=0; tc<t; tc++) {
int n = scan.nextInt(); // ํ์ ์
int m = scan.nextInt(); // ํ์์ด ๋ฐ์ ์ ์๋ ์ต๋์คจ์
int sum = 0; // ๋ชจ๋ ํ์์ ์ ์ ํฉ
int ans = 0; // ์ ๋ต
int[] arr = new int[n];
for(int i=0; i<n; i++) {
arr[i] = scan.nextInt();
sum += arr[i];
}
ans = (sum>=m) ? m : sum;
System.out.println(ans);
}
scan.close();
}
}
ํ์ด
๋ชจ๋ ํ์ ์ ์์ ํฉ์ด m๋ณด๋ค ํฌ๊ฑฐ๋๊ฐ์ผ๋ฉด m์, ๋ฏธ๋ง์ด๋ฉด sum์ ์ถ๋ ฅ
๋ฐ์ํ
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 14502๋ฒ: ์ฐ๊ตฌ์(DFS, BFS, ์์ ํ์) (0) | 2020.04.08 |
---|---|
[๋ฐฑ์ค] 1188๋ฒ: ์์ํ๋ก ๊ฐ(๊ตฌํ, ์ต๋๊ณต์ฝ์) (0) | 2020.04.08 |
[๋ฐฑ์ค] 10709๋ฒ: ๊ธฐ์์บ์คํฐ(๊ตฌํ) (0) | 2020.04.07 |
[๋ฐฑ์ค] 1021๋ฒ: ํ์ ํ๋ ํ (0) | 2020.04.07 |
[๋ฐฑ์ค] 10026๋ฒ: ์ ๋ก์์ฝ(DFS) (0) | 2020.04.06 |
๋๊ธ