Submission #1355846
Source Code Expand
import java.util.HashMap; import java.util.Map.Entry; import java.util.Optional; import java.util.Scanner; import java.util.stream.IntStream; public class Main{ static final Scanner s=new Scanner(System.in); static IntStream REPS(int v){ return IntStream.range(0,v); } static IntStream REPS(int l,int r) { return IntStream.rangeClosed(l,r); } static IntStream INS(int n) { return REPS(n).map(i->getInt()); } static int getInt(){ return Integer.parseInt(s.next()); } public static void main(String[]__){ int k=getInt(),t=getInt(); HashMap<Integer,Integer> m=new HashMap<>(); REPS(t).forEach(i->m.put(i,getInt())); int l=-1,c=0; for(int i=0;i<k;i++) { final int last=l; Optional<Integer> hoge=m.entrySet().stream() .filter(o->o.getKey()!=last&&o.getValue()!=0) .max(Entry.comparingByValue()) .map(Entry::getKey); if(!hoge.isPresent()) c++; m.merge((l=hoge.orElse(last)),-1,Integer::sum); } System.out.println(c); } }
Submission Info
Submission Time | |
---|---|
Task | B - K Cakes |
User | fal_rnd |
Language | Java8 (OpenJDK 1.8.0) |
Score | 200 |
Code Size | 1027 Byte |
Status | AC |
Exec Time | 286 ms |
Memory | 28884 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 185 ms | 24660 KB |
0_001.txt | AC | 183 ms | 24532 KB |
0_002.txt | AC | 185 ms | 25552 KB |
1_003.txt | AC | 286 ms | 28884 KB |
1_004.txt | AC | 201 ms | 24532 KB |
1_005.txt | AC | 190 ms | 25044 KB |
1_006.txt | AC | 199 ms | 26836 KB |
1_007.txt | AC | 199 ms | 25168 KB |
1_008.txt | AC | 183 ms | 26324 KB |
1_009.txt | AC | 208 ms | 24532 KB |