inhuman_Arif

HE01

Feb 6th, 2023
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) throws IOException {
  6. //        System.setIn(new FileInputStream(new File("/home/arif/Documents/inout/input.txt")));
  7. //        System.setOut(new PrintStream(new File("/home/arif/Documents/inout/output.txt")));
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int tc = scanner.nextInt();
  11.         while (tc-- >0){
  12.             int n = scanner.nextInt();
  13.             int[] a = new int[n];
  14.             int[] u = new int[n];
  15.             List <Integer> listMax = new ArrayList<>();
  16.             for (int i=0;i<n;i++)
  17.                 a[i] = scanner.nextInt();
  18.             for (int i=0;i<n;i++)
  19.                 u[i] = scanner.nextInt();
  20.             listMax.add(u[0]);
  21.             int k = 0;
  22.             for (int i=0;i<n-1;i++){
  23.                 if (a[i]==a[i+1])
  24.                     listMax.set(k,Math.max(listMax.get(k),u[i+1]));
  25.                 else {
  26.                     listMax.set(k,Math.max(listMax.get(k),u[i]));
  27.                     k++;
  28.                     listMax.add(u[i+1]);
  29.                 }
  30.             }
  31.             long sum = 0;
  32.             for (int i:listMax)
  33.                 sum+=i;
  34.             System.out.println(sum);
  35.         }
  36.  
  37.         scanner.close();
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment