Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws IOException {
- // System.setIn(new FileInputStream(new File("/home/arif/Documents/inout/input.txt")));
- // System.setOut(new PrintStream(new File("/home/arif/Documents/inout/output.txt")));
- Scanner scanner = new Scanner(System.in);
- int tc = scanner.nextInt();
- while (tc-- >0){
- int n = scanner.nextInt();
- int[] a = new int[n];
- int[] u = new int[n];
- List <Integer> listMax = new ArrayList<>();
- for (int i=0;i<n;i++)
- a[i] = scanner.nextInt();
- for (int i=0;i<n;i++)
- u[i] = scanner.nextInt();
- listMax.add(u[0]);
- int k = 0;
- for (int i=0;i<n-1;i++){
- if (a[i]==a[i+1])
- listMax.set(k,Math.max(listMax.get(k),u[i+1]));
- else {
- listMax.set(k,Math.max(listMax.get(k),u[i]));
- k++;
- listMax.add(u[i+1]);
- }
- }
- long sum = 0;
- for (int i:listMax)
- sum+=i;
- System.out.println(sum);
- }
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment