git reimport
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package chelper;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class TaskB extends SimpleSavingChelperSolution {
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
class MultiLong implements Comparable<MultiLong> {
|
||||
long i;
|
||||
long x;
|
||||
|
||||
public MultiLong(long i, long x) {
|
||||
this.i = i;
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MultiLong multiLong = (MultiLong) o;
|
||||
return i == multiLong.i &&
|
||||
x == multiLong.x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(i, x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MultiLong o) {
|
||||
int t = Long.compare(x, o.x);
|
||||
if (t != 0) {
|
||||
return t;
|
||||
}
|
||||
|
||||
return Long.compare(i, o.i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
|
||||
TreeSet<MultiLong> set = new TreeSet<>();
|
||||
|
||||
long[] v = in.nextLongArray(n);
|
||||
long[] t = in.nextLongArray(n);
|
||||
|
||||
long corr = 0;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
long res = 0;
|
||||
|
||||
set.add(new MultiLong(i, v[i] + corr));
|
||||
|
||||
Iterator<MultiLong> iterator = set.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
long x = iterator.next().x - corr;
|
||||
|
||||
if (x <= t[i]) {
|
||||
res += x;
|
||||
iterator.remove();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
res += set.size() * t[i];
|
||||
|
||||
corr += t[i];
|
||||
|
||||
out.print(res + " ");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user