Language: C++

using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Main()
    {
        int N = NextInt();
        int Q = NextInt();
        // zip[圧縮後] = 元座標
        Dictionary<int, int> zip = new Dictionary<int, int>();
        List<int[]> stx = Enumerable.Range(0, N).Select(v => LineInt()).ToList();
        stx.Sort((x, y) => x[2].CompareTo(y[2]));
        int key = 0;
        int num = -INF;
        List<int[]> Event = new List<int[]>();
        for (int i = 0; i < N; i++)
        {
            if (num != stx[i][2]) { zip[key] = stx[i][2]; key++; num = stx[i][2]; }
            Event.Add(new int[3] { stx[i][0] - stx[i][2], 0, key });
            Event.Add(new int[3] { stx[i][1] - stx[i][2], 1, key });
        }
        Event.Sort((x, y) => x[0].CompareTo(y[0]));
        MinTree MT = new MinTree(key + 1, 0);
        List<int> ans = new List<int>();
        int index = 0;
        foreach (var e in Enumerable.Range(0, Q).Select(v => NextInt()))
        {
            //Dまでに行われるイベントを済ます
            while (index != 2 * N && e >= Event[index][0])
            {
                if (Event[index][1] == 0) MT.Add(Event[index][2], 1);
                else if (Event[index][1] == 1) MT.Add(Event[index][2], -1);
                index++;
            }
            int ind = MT.MLS(1);
            ans.Add(ind == -1 ? -1 : zip[ind - 1]);
        }
        ans.ForEach(Console.WriteLine);
    }
}

public class MinTree
{
    private List<int> table = new List<int>();
    private static int size = 1;
    private static int high = 1;
    public MinTree(int n, int k = 0)
    {
        while (size < n) size *= 2;
        high = (int)Math.Log(size, 2);
        for (int i = 0; i < 2 * size - 1; i++) table.Add(k);
    }
    public void Add(int x, int v)
    {
        x += size - 1;
        table[x] += v;
        table[x] = Math.Max(0, table[x]);
        while (x != 0)
        {
            x = (x % 2 == 0 ? x / 2 - 1 : x / 2);
            table[x] = table[x * 2 + 1] + table[x * 2 + 2];
        }
    }
    public int MLS(int k)
    {
        if (table.First() == 0) return -1;
        int index = 0;
        for (int y = 0; y < high; y++)
        {
            int left = index * 2 + 1;
            int right = index * 2 + 2;
            if (table[left] >= k) index = left;
            else { k -= table[left]; index = right; }
        }
        return index - size + 1;
    }
    public int GetValue(int k) { return table[k + size - 1]; }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Collections.Generic;
      |       ^~~~~~
a.cc:3:7: error: expected nested-name-specifier before 'System'
    3 | using System.Linq;
      |       ^~~~~~
a.cc:4:7: error: expected nested-name-specifier before 'static'
    4 | using static Input;
      |       ^~~~~~
a.cc:6:1: error: expected unqualified-id before 'public'
    6 | public class Prog
      | ^~~~~~
a.cc:47:1: error: expected unqualified-id before 'public'
   47 | public class MinTree
      | ^~~~~~
a.cc:85:1: error: expected unqualified-id before 'public'
   85 | public class Input
      | ^~~~~~