fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. int n = scanner.nextInt();
  7. scanner.nextLine(); // Consume newline
  8. String colors = scanner.nextLine().trim();
  9. long sumR = 0, sumG = 0, sumB = 0;
  10. for (int i = 0; i < n; i++) {
  11. long w = scanner.nextLong();
  12. char c = colors.charAt(i);
  13. if (c == 'R') sumR += w;
  14. else if (c == 'G') sumG += w;
  15. else sumB += w;
  16. }
  17. long total = sumR + sumG + sumB;
  18. long max = Math.max(sumR, Math.max(sumG, sumB));
  19. System.out.println(total - max);
  20. }
  21. }
Success #stdin #stdout 0.12s 54496KB
stdin
4
RGBR
3 1 2 4 
1 2
2 3
2 4
stdout
3