Submission #278292
Source Code Expand
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
LinkedList<Long> list = new LinkedList<Long>();
list.add(sc.nextLong());
long cost = Long.MAX_VALUE;
long sum = 0;
for(int i = 1; i <= n; ++i){
long val = sc.nextLong();
ListIterator<Long> iterator = list.listIterator();
boolean addedFlag = false;
long target = 0;
while (iterator.hasNext()) {
target = iterator.next();
long diff = getDiff(target, val);
if(cost > diff){
cost = diff;
}
if (target > val) {
iterator.previous();
iterator.add(val);
addedFlag = true;
break;
}
}
if(!addedFlag){
iterator.add(val);
cost= val - target;
}
sum += cost;
}
System.out.println(sum);
sc.close();
}
public static long getDiff(long l1, long l2) {
if (l1 >= l2) {
return l1 - l2;
} else {
return l2 - l1;
}
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - コミュニケーション能力(Communication Ability) |
| User | fdash06 |
| Language | Java (OpenJDK 1.7.0) |
| Score | 0 |
| Code Size | 1507 Byte |
| Status | WA |
| Exec Time | 2039 ms |
| Memory | 37636 KiB |
Judge Result
| Set Name | all | ||||||
|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 500 | ||||||
| Status |
|
| Set Name | Test Cases |
|---|---|
| all | subtask0_sample01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| subtask0_sample01.txt | AC | 449 ms | 23164 KiB |
| subtask1_01.txt | WA | 446 ms | 23220 KiB |
| subtask1_02.txt | WA | 452 ms | 23220 KiB |
| subtask1_03.txt | WA | 445 ms | 23172 KiB |
| subtask1_04.txt | TLE | 2038 ms | 37384 KiB |
| subtask1_05.txt | TLE | 2038 ms | 37120 KiB |
| subtask1_06.txt | TLE | 2036 ms | 37636 KiB |
| subtask1_07.txt | TLE | 2039 ms | 36444 KiB |
| subtask1_08.txt | TLE | 2039 ms | 36532 KiB |
| subtask1_09.txt | TLE | 2038 ms | 37532 KiB |
| subtask1_10.txt | TLE | 2039 ms | 37560 KiB |
| subtask1_11.txt | TLE | 2038 ms | 36944 KiB |
| subtask1_12.txt | TLE | 2038 ms | 36432 KiB |
| subtask1_13.txt | TLE | 2039 ms | 36576 KiB |
| subtask1_14.txt | TLE | 2037 ms | 36468 KiB |
| subtask1_15.txt | TLE | 2039 ms | 36076 KiB |