-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |