Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- class Codechef
- {
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- long T = Integer.parseInt(br.readLine().trim());
- for (long t = 0; t < T; t++) {
- long n = Integer.parseInt(br.readLine().trim());
- long influence[] = new long[(int) n];
- String[] firstLine = br.readLine().split(" ");
- for (int i = 0; i < firstLine.length; i++) {
- influence[i] = Integer.parseInt(firstLine[i]);
- }
- findVote(influence, n);
- }
- }
- // [1,2,3,6,4]
- private static long[] findVote(long[] influence, long n) {
- long[] voters = new long[(int) n];
- for (long i = 0; i < influence.length; i++) {
- long l = i - 1, r = i + 1, s = 0;
- while (s <= influence[(int) i] && r <= n - 1) {
- s += influence[(int) r++];
- }
- if (i < n - 1) {
- voters[(int) i]--;
- voters[(int) (r - 1)]++;
- }
- s = 0;
- while (s <= influence[(int) i] && l >= 0) {
- s += influence[(int) l--];
- }
- if (i > 0) {
- voters[(int) (i - 1)]++;
- }
- if (l >= 0) {
- voters[(int) l]--;
- }
- }
- for (long i = voters.length - 2; i >= 0; i--) {
- voters[(int) i] += voters[(int) (i + 1)];
- }
- for (long i : voters) {
- System.out.print(i + " ");
- }
- System.out.println();
- return voters;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement