| Task: | Food |
| Sender: | PILIPOJAT!! |
| Submission time: | 2016-09-13 18:24:31 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.37 s | details |
| #2 | ACCEPTED | 0.44 s | details |
| #3 | ACCEPTED | 0.28 s | details |
| #4 | ACCEPTED | 0.38 s | details |
| #5 | ACCEPTED | 0.13 s | details |
| #6 | ACCEPTED | 0.36 s | details |
| #7 | ACCEPTED | 0.28 s | details |
| #8 | ACCEPTED | 0.38 s | details |
| #9 | ACCEPTED | 0.32 s | details |
| #10 | ACCEPTED | 0.40 s | details |
| #11 | ACCEPTED | 0.20 s | details |
| #12 | ACCEPTED | 0.34 s | details |
| #13 | ACCEPTED | 0.14 s | details |
| #14 | ACCEPTED | 0.35 s | details |
| #15 | ACCEPTED | 0.26 s | details |
| #16 | ACCEPTED | 0.35 s | details |
| #17 | ACCEPTED | 0.38 s | details |
| #18 | ACCEPTED | 0.37 s | details |
| #19 | ACCEPTED | 0.36 s | details |
| #20 | ACCEPTED | 0.36 s | details |
Code
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
*
* @author guest-kidtfF
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
List<Friend> friends = new ArrayList<>();
IO io = new IO();
final int max = io.nextInt();
for(int i = 0; i < max; i++) {
long c = io.nextLong();
long d = io.nextLong();
friends.add(new Friend(c, d));
}
Collections.sort(friends);
long roll = 0;
long total = 0;
if(friends.size() == 1) {
System.out.println(friends.get(0).getCallTime() + friends.get(0).getDeliveryTime());
System.exit(0);
}
/*for(Friend f : friends) {
if(roll == 0) {
total += f.getDeliveryTime();
roll = f.getDeliveryTime();
} else {
roll -= f.getDeliveryTime();
}
roll -= f.getCallTime();
if(roll < 0) {
total += Math.abs(roll);
roll = 0;
}
}*/
//hc koodi alkaa taas täst
long time=0;
long boobs=0; //hc muuttuja
for(Friend f : friends) {
time += f.getCallTime();
if(boobs < f.getDeliveryTime() + time) {
boobs = f.getDeliveryTime() + time;
}
}
System.out.println(boobs);
}
private static class Friend implements Comparable<Friend> {
private long callTime;
private long deliverytime;
public Friend(long callTime, long deliverytime) {
this.callTime = callTime;
this.deliverytime = deliverytime;
}
public long getDeliveryTime() {
return deliverytime;
}
public long getCallTime() {
return callTime;
}
@Override
public String toString() {
return callTime + ", " + deliverytime;
}
@Override
public int compareTo(Friend o) {
if(o.getDeliveryTime() == getDeliveryTime()) {
return o.getCallTime() > getCallTime() ? (o.getCallTime() == getCallTime() ? 0 : -1) : 1;
}
return o.getDeliveryTime() > getDeliveryTime() ? 1 : -1;
}
}
public static class IO extends PrintWriter {
private InputStreamReader r;
private static final int BUFSIZE = 1 << 15;
private char[] buf;
private int bufc;
private int bufi;
private StringBuilder sb;
public IO() {
super(new BufferedOutputStream(System.out));
r = new InputStreamReader(System.in);
buf = new char[BUFSIZE];
bufc = 0;
bufi = 0;
sb = new StringBuilder();
}
private void fillBuf() throws IOException {
bufi = 0;
bufc = 0;
while(bufc == 0) {
bufc = r.read(buf, 0, BUFSIZE);
if(bufc == -1) {
bufc = 0;
return;
}
}
}
private boolean pumpBuf() throws IOException {
if(bufi == bufc) {
fillBuf();
}
return bufc != 0;
}
private boolean isDelimiter(char c) {
return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
}
private void eatDelimiters() throws IOException {
while(true) {
if(bufi == bufc) {
fillBuf();
if(bufc == 0) throw new RuntimeException("IO: Out of input.");
}
if(!isDelimiter(buf[bufi])) break;
++bufi;
}
}
public String next() {
try {
sb.setLength(0);
eatDelimiters();
int start = bufi;
while(true) {
if(bufi == bufc) {
sb.append(buf, start, bufi - start);
fillBuf();
start = 0;
if(bufc == 0) break;
}
if(isDelimiter(buf[bufi])) break;
++bufi;
}
sb.append(buf, start, bufi - start);
return sb.toString();
} catch(IOException e) {
throw new RuntimeException("IO.next: Caught IOException.");
}
}
public int nextInt() {
try {
int ret = 0;
eatDelimiters();
boolean positive = true;
if(buf[bufi] == '-') {
++bufi;
if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
positive = false;
}
boolean first = true;
while(true) {
if(!pumpBuf()) break;
if(isDelimiter(buf[bufi])) {
if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
break;
}
first = false;
if(buf[bufi] >= '0' && buf[bufi] <= '9') {
if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
ret *= 10;
ret -= (int)(buf[bufi] - '0');
if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
} else {
throw new RuntimeException("IO.nextInt: Invalid int.");
}
++bufi;
}
if(positive) {
if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
ret = -ret;
}
return ret;
} catch(IOException e) {
throw new RuntimeException("IO.nextInt: Caught IOException.");
}
}
public long nextLong() {
try {
long ret = 0;
eatDelimiters();
boolean positive = true;
if(buf[bufi] == '-') {
++bufi;
if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
positive = false;
}
boolean first = true;
while(true) {
if(!pumpBuf()) break;
if(isDelimiter(buf[bufi])) {
if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
break;
}
first = false;
if(buf[bufi] >= '0' && buf[bufi] <= '9') {
if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
ret *= 10;
ret -= (long)(buf[bufi] - '0');
if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
} else {
throw new RuntimeException("IO.nextLong: Invalid long.");
}
++bufi;
}
if(positive) {
if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
ret = -ret;
}
return ret;
} catch(IOException e) {
throw new RuntimeException("IO.nextLong: Caught IOException.");
}
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 89384 681692778 846930887 957747794 714636916 719885387 424238336 596516650 649760493 ... |
| correct output |
|---|
| 42147058766965 |
| user output |
|---|
| 42147058766965 |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 100000 359160035 411697972 968780718 734301045 453848409 688724883 164253927 734806101 ... |
| correct output |
|---|
| 47222273083201 |
| user output |
|---|
| 47222273083201 |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 44480 362933728 933793117 891136996 323613975 94635258 248274880 6815710 724743065 ... |
| correct output |
|---|
| 20844945142934 |
| user output |
|---|
| 20844945142934 |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 100000 793185233 288183591 37963413 618955541 431443272 198177617 496048961 69352054 ... |
| correct output |
|---|
| 47102072350982 |
| user output |
|---|
| 47102072350982 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 3155 618827474 60542179 527933441 114537664 70733156 243416943 969550074 152211461 ... |
| correct output |
|---|
| 1500343496945 |
| user output |
|---|
| 1500343496945 |
Test 6
Verdict: ACCEPTED
| input |
|---|
| 100000 910963441 143294384 713266793 860151529 993281319 41804445 373567075 274241561 ... |
| correct output |
|---|
| 46887883327574 |
| user output |
|---|
| 46887883327574 |
Test 7
Verdict: ACCEPTED
| input |
|---|
| 28162 134919079 814389249 462178596 518815506 129524528 476439372 293505853 399662455 ... |
| correct output |
|---|
| 13252390774552 |
| user output |
|---|
| 13252390774552 |
Test 8
Verdict: ACCEPTED
| input |
|---|
| 100000 116238406 23950922 192719099 161355170 791155851 144252659 968021758 429552179 ... |
| correct output |
|---|
| 47099509771247 |
| user output |
|---|
| 47099509771247 |
Test 9
Verdict: ACCEPTED
| input |
|---|
| 80676 955479656 607661572 406105372 205043535 439059576 504415953 198026879 574037487 ... |
| correct output |
|---|
| 38150726947166 |
| user output |
|---|
| 38150726947166 |
Test 10
Verdict: ACCEPTED
| input |
|---|
| 100000 719589006 144908765 816296155 975791631 306585999 463857005 111974616 31151282 ... |
| correct output |
|---|
| 46986601423372 |
| user output |
|---|
| 46986601423372 |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 52870 94072776 697217561 312414108 163547056 525050122 874742904 811284897 582428307 ... |
| correct output |
|---|
| 24949625769940 |
| user output |
|---|
| 24949625769940 |
Test 12
Verdict: ACCEPTED
| input |
|---|
| 100000 24951805 862725068 133221224 988570326 917319027 475953991 221262630 524912601 ... |
| correct output |
|---|
| 46925181986472 |
| user output |
|---|
| 46925181986472 |
Test 13
Verdict: ACCEPTED
| input |
|---|
| 4111 957981573 241070686 651592347 758396414 832226666 596050875 292541224 25929816 ... |
| correct output |
|---|
| 1926884537566 |
| user output |
|---|
| 1926884537566 |
Test 14
Verdict: ACCEPTED
| input |
|---|
| 100000 251725245 77171349 90577136 473745863 167654421 354782932 923594762 650005823 ... |
| correct output |
|---|
| 46941247798964 |
| user output |
|---|
| 46941247798964 |
Test 15
Verdict: ACCEPTED
| input |
|---|
| 35135 858577961 405718020 798186777 119257724 864602943 904466622 864409840 555139510 ... |
| correct output |
|---|
| 16520298783731 |
| user output |
|---|
| 16520298783731 |
Test 16
Verdict: ACCEPTED
| input |
|---|
| 100000 188509002 200018574 287247908 822624098 101701451 283835672 457476331 88054113 ... |
| correct output |
|---|
| 46970995271443 |
| user output |
|---|
| 46970995271443 |
Test 17
Verdict: ACCEPTED
| input |
|---|
| 99800 631858331 746120730 76109035 639667425 514304658 612831726 479354598 268768336 ... |
| correct output |
|---|
| 46996558109334 |
| user output |
|---|
| 46996558109334 |
Test 18
Verdict: ACCEPTED
| input |
|---|
| 100000 86697323 903699564 672895479 975551966 949280629 265984694 298793170 921622295 ... |
| correct output |
|---|
| 47061738332320 |
| user output |
|---|
| 47061738332320 |
Test 19
Verdict: ACCEPTED
| input |
|---|
| 89912 220922738 763777725 516271940 238232413 34685422 248167527 465168443 70301610 ... |
| correct output |
|---|
| 42258460387706 |
| user output |
|---|
| 42258460387706 |
Test 20
Verdict: ACCEPTED
| input |
|---|
| 100000 383409812 499086892 931098608 115082744 52074979 597961407 31693436 492333918 ... |
| correct output |
|---|
| 47022483606892 |
| user output |
|---|
| 47022483606892 |
