Skip to content

Commit

Permalink
Feat: Add solution of #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Dltmd202 committed Jul 22, 2022
1 parent 86874e1 commit 7b65241
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/BaekJoon/Dltmd202/2805/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();

public static void main(String[] args) throws IOException {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int[] data = new int[n];

st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
data[i] = Integer.parseInt(st.nextToken());
}

int left = 0;
int right = Arrays.stream(data).max().getAsInt();

while (left <= right){
long mid = (left + right) / 2;

long cut = cut(data, mid);

if(cut >= m){
left = (int) (mid + 1);
} else {
right = (int) (mid - 1);
}
}
System.out.println(right);
}


public static long cut(int[] data, long length){
return Arrays.stream(data)
.filter(t -> t > length)
.mapToLong(t -> t - length)
.sum();
}
}
24 changes: 24 additions & 0 deletions src/BaekJoon/Dltmd202/2839/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();

public static void main(String[] args) throws IOException {
int n = Integer.parseInt(br.readLine());

System.out.println(search(n));
}

private static int search(int n) {
for (int i = n / 5; i >= 0; i--) {
int left = n - (i * 5);
for (int j = left / 3; j >= 0; j--) {
if(left - (j * 3) == 0) return i + j;
}
}
return -1;
}
}

0 comments on commit 7b65241

Please sign in to comment.