git reimport
This commit is contained in:
42
archive/2017.10/2017.10.27 - unsorted/D.java
Normal file
42
archive/2017.10/2017.10.27 - unsorted/D.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class D extends SimpleSavingChelperSolution {
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
|
||||
long[] a = in.nextLongArray(n);
|
||||
|
||||
Arrays.sort(a);
|
||||
|
||||
long t = 0;
|
||||
long ans = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
t += a[i];
|
||||
}
|
||||
|
||||
int i = n - 1;
|
||||
while (i > 0) {
|
||||
ans += t;
|
||||
t -= a[i];
|
||||
i--;
|
||||
if (i > 0) {
|
||||
t -= a[i];
|
||||
i--;
|
||||
}
|
||||
}
|
||||
out.println(ans);
|
||||
}
|
||||
}
|
36
archive/2017.10/2017.10.27 - unsorted/D.task
Normal file
36
archive/2017.10/2017.10.27 - unsorted/D.task
Normal file
@@ -0,0 +1,36 @@
|
||||
1 D
|
||||
6 SINGLE
|
||||
8 STANDARD
|
||||
9 input.txt
|
||||
8 STANDARD
|
||||
10 output.txt
|
||||
3
|
||||
0
|
||||
9 4
|
||||
2 3 4 5
|
||||
2 19
|
||||
1
|
||||
1
|
||||
7 3
|
||||
1 2 3
|
||||
1 6
|
||||
1
|
||||
2
|
||||
13 6
|
||||
1 4 4 4 4 4
|
||||
2 38
|
||||
1
|
||||
11 src/chelper
|
||||
16 -Xmx256m -Xss64m
|
||||
4 Main
|
||||
9 chelper.D
|
||||
39 net.egork.chelper.checkers.TokenChecker
|
||||
0
|
||||
0
|
||||
10 2017.10.27
|
||||
0
|
||||
1
|
||||
14 io.InputReader
|
||||
15 io.OutputWriter
|
||||
0
|
||||
0
|
62
archive/2017.10/2017.10.27 - unsorted/С.java
Normal file
62
archive/2017.10/2017.10.27 - unsorted/С.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class С extends SimpleSavingChelperSolution {
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
|
||||
int[] a = new int[n];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
a[i] = in.nextInt() - 1;
|
||||
}
|
||||
|
||||
boolean[] visited = new boolean[n];
|
||||
|
||||
List<Integer> b = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (visited[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int t = i;
|
||||
int c = 0;
|
||||
while (!visited[t]) {
|
||||
visited[t] = true;
|
||||
t = a[t];
|
||||
c++;
|
||||
}
|
||||
b.add(c);
|
||||
}
|
||||
|
||||
Collections.sort(b);
|
||||
|
||||
if (b.size() >= 2) {
|
||||
int x = b.remove(b.size() - 1);
|
||||
int y = b.remove(b.size() - 1);
|
||||
b.add(x + y);
|
||||
}
|
||||
|
||||
long res = 0;
|
||||
for (Integer integer : b) {
|
||||
res += ((long) integer) * ((long) integer);
|
||||
}
|
||||
|
||||
out.println(res);
|
||||
}
|
||||
}
|
56
archive/2017.10/2017.10.27 - unsorted/С.task
Normal file
56
archive/2017.10/2017.10.27 - unsorted/С.task
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user