Untitled
unknown
java
a year ago
1.9 kB
1
Indexable
Never
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int с = scanner.nextInt(); int d = scanner.nextInt(); scanner.nextLine(); Set<Node> numbers = new TreeSet<>(Comparator.comparing(Node::getAbs)); for (int i = 0; i < n; i++) { Node node = new Node(i, scanner.nextInt()); numbers.add(node); } // for (int i = 0; i < с; i++) { // Node first = numbers.iterator().next(); // numbers.remove(first); // first.setValue(first.getValue() - d); // numbers.add(first); // } System.out.println(numbers); } public static class Node { private final int index; private int value; public Node(int index) { this.index = index; } public Node(int index, int value) { this.index = index; this.value = value; } public int getIndex() { return index; } public int getValue() { return value; } public int getAbs() { return Math.abs(value); } public void setValue(int value) { this.value = value; } @Override public String toString() { return "Node{" + "index=" + index + ", value=" + value + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Node node = (Node) o; return index == node.index && value == node.value; } @Override public int hashCode() { return Objects.hash(index, value); } } }