1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
public class Main {
public static void main(String[]args) {
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int m=scan.nextInt();
int arr[]=new int[n];
for(int a=0;a<n;a++) {
arr[a]=scan.nextInt();
}
int num;//세 수를 합한 수
int max=0;//제일 m값과 가까운 값
for(int i=0;i<n-2;i++) {
for(int j=i+1;j<n-1;j++) {
for(int k=j+1;k<n;k++) {
num=arr[i]+arr[j]+arr[k];
if(num<=m && num>max)
max=num;
}
}
}
System.out.println(max);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
c++이랑 알고리즘 토씨하나 안 다르게 했는데 왜 덩치가 더 클까
'Algorithm > BOJ' 카테고리의 다른 글
[BOJ/C++] 단계별로 풀어보기- 입출력과 사칙연산 (0) | 2020.05.27 |
---|---|
[BOJ/C++]4344번 평균은 넘겠지 (0) | 2020.03.09 |
[BOJ/Java]8958번 OX퀴즈 (0) | 2020.03.09 |
[BOJ/C++] 3052번 나머지 (0) | 2020.01.31 |
[BOJ/C++] 2798번 블랙잭 (0) | 2020.01.31 |
댓글