Advertisement
Guest User

Untitled

a guest
May 27th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace B
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<Int32, Int32> dict = new Dictionary<Int32, Int32>();
  14.  
  15.             Int32 n = Int32.Parse(Console.ReadLine());            
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 Int32[] input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
  19.                 dict[input[0]] = input[1];
  20.             }
  21.  
  22.             Int32 m = Int32.Parse(Console.ReadLine());
  23.             for (int i = 0; i < m; i++)
  24.             {
  25.                 Int32[] input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
  26.                 Int32 b = input[0];
  27.                 Int32 y = input[1];
  28.                 if (!dict.ContainsKey(b))
  29.                 {
  30.                     dict[b] = y;
  31.                     continue;
  32.                 }
  33.  
  34.                 if (dict[b] < y)
  35.                     dict[b] = y;
  36.             }
  37.  
  38.             Int64 result = 0;
  39.             foreach (Int32 value in dict.Values)
  40.             {
  41.                 result += value;
  42.             }
  43.  
  44.             Console.WriteLine(result);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement