git reimport
This commit is contained in:
64
archive/2017.03/2017.03.04 - unsorted/B.java
Normal file
64
archive/2017.03/2017.03.04 - unsorted/B.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
|
||||
public class B {
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
int n = in.nextInt();
|
||||
int pol = in.nextInt();
|
||||
if (pol == 0) {
|
||||
out.print(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Chelik> cheliki = new ArrayList<>();
|
||||
for (int i = 2; i <= n; i++) {
|
||||
cheliki.add(new Chelik(i, in.nextInt()));
|
||||
}
|
||||
Collections.sort(cheliki);
|
||||
cheliki.add(0, new Chelik(1, pol));
|
||||
|
||||
List<String> answer = new ArrayList<>();
|
||||
|
||||
int left = 0;
|
||||
for (int right = 1; right < n; right++) {
|
||||
if (left == right) {
|
||||
out.print(-1);
|
||||
return;
|
||||
}
|
||||
if (cheliki.get(left).dzun > 0) {
|
||||
answer.add(cheliki.get(left).index + " " + cheliki.get(right).index);
|
||||
cheliki.get(left).dzun--;
|
||||
} else {
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
}
|
||||
|
||||
out.println(answer.size());
|
||||
for (String s : answer) {
|
||||
out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
class Chelik implements Comparable<Chelik> {
|
||||
int index;
|
||||
int dzun;
|
||||
|
||||
public Chelik(int index, int dzun) {
|
||||
this.index = index;
|
||||
this.dzun = dzun;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Chelik o) {
|
||||
return Integer.compare(o.dzun, dzun);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user