Go: package main

import (
	"fmt"
	"sort"
)

type Datum struct {
	EraName      string
	EraBasedYear int64
	WesternYear  int64
}

const Unknown = "Unknown"

func lowerBound(data []*Datum, westernYearBorder int64) int {
	imin := -1
	imax := len(data)
	for imax-imin > 1 {
		imid := (imax + imin) / 2
		if data[imid].WesternYear >= westernYearBorder {
			imax = imid
		} else {
			imin = imid
		}
	}
	return imax
}

func solve(n, q int) {
	data := make([]*Datum, 0, n)
	for index := 0; index < n; index++ {
		datum := Datum{}
		fmt.Scan(&datum.EraName, &datum.EraBasedYear, &datum.WesternYear)
		data = append(data, &datum)
	}
	sort.Slice(data, func(i, j int) bool {
		return data[i].WesternYear < data[j].WesternYear
	})
	for cnt := 0; cnt < q; cnt++ {
		var query int64
		fmt.Scan(&query)
		var index int
		if index = lowerBound(data, query); index == n {
			fmt.Println(Unknown)
			continue
		}
		possibleDatum := data[index]
		if possibleDatum.WesternYear-query > possibleDatum.EraBasedYear-1 {
			fmt.Println(Unknown)
			continue
		}
		ans := possibleDatum.EraBasedYear - (possibleDatum.WesternYear - query)
		fmt.Println(possibleDatum.EraName, ans)
	}
}

func main() {
	for {
		var n, q int
		if fmt.Scan(&n, &q); n == 0 && q == 0 {
			break
		}
		solve(n, q)
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int N, Q;
    for (int N, Q; cin >> N >> Q and N and Q;) {
        vector<pair<int,pair<string, int>>> p;
        rep(i, N) {
            string e;
            int a, b;
            cin >> e >> a >> b;
            p.push_back(make_pair(b, make_pair(e, a)));
        }
        sort(p.begin(), p.end(),[](const pair<int, pair<string, int>>& a, const pair<int, pair<string, int>>& b) {
            return a.first < b.first;
        });
        rep(i, Q) {
            int d;
            cin >> d;

            auto itr = lower_bound(p.begin(), p.end(), make_pair(d, make_pair("a", 0)), [](const pair<int, pair<string, int>>& a, const pair<int, pair<string, int>>& b) {
                return a.first < b.first;
            });

            if (itr == p.end()) {
                cout << "Unknown" << endl;
            }
            else {
                auto tmp = *itr;
                if (tmp.first-tmp.second.second+1 <= d and d <= tmp.first) {
                    cout << tmp.second.first << ' ' << tmp.second.second - (tmp.first - d) << endl;
                }
                else {
                    cout << "Unknown" << endl;
                }
            }
        }
    }
    return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int N, Q;
	while(cin >> N >> Q, N) {
		vs name(N);
		vvi year(N, vi(2));

		REP(i, N) {
			cin >> name[i] >> year[i][0] >> year[i][1];
			year[i][0] = year[i][1]-year[i][0]+1;
		}

		REP(i, Q) {
			int y;
			cin >> y;
			REP(j, N) {
				if(year[j][0] <= y && y <= year[j][1]) {
					cout << name[j] << " " << y-year[j][0]+1 << endl;
					goto next;
				}
			}
			cout << "Unknown" << endl;
			next:;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>

using namespace std;

#define MAX 10000000

int main(){

	string data[MAX+1];
	int yeda[MAX+1];
	string en;
	int N,Q,eby,wy;
	int qu;
	string tm;

	while(1){
		cin>>N>>Q;
		if(N==0&&Q==0) break;
		for(int i=1;i<=MAX;i++){
			data[i]="Unkown";
			yeda[i]=-1;
		}
		for(int i=0;i<N;i++){
			cin>>en>>eby>>wy;
			for(int i=0;i<10;i++){
				data[wy-eby+1+i]=en;
				yeda[wy-eby+1+i]=i+1;
			}
		}
		for(int i=0;i<Q;i++){
			cin>>qu;
			if(data[qu]!="Unkown") cout<<data[qu]<<" "<<yeda[qu]<<endl;
			else cout<<"Unkown"<<endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<queue>
using namespace std;

priority_queue<int> q;
struct CC
{
    int m,l,k;
    bool yes;
}cos[1010];
int T,N;

bool pd(int x)
{
    for (int i=0;i<N;i++) cos[i].yes=false;
    while (!q.empty()) q.pop();
    for (int i=0;i<x;i++)
    {
        q.push(0);
    }
    int tot=0;
    while (tot<N)
    {
      //  if (q.empty()) return false;
        int recent=2000000000,id;
        int u=-q.top();
        bool fg=false;
        for (int i=0;i<N;i++)
        if (!cos[i].yes)
        {
            if (u%(cos[i].l+cos[i].k)<=cos[i].l && u+cos[i].k<=T)
            {
                cos[i].yes=true;
                tot++;
                u+=cos[i].m;
                q.pop();
                q.push(-u);
                fg=true;
                break;
            }
            if (recent>(u/(cos[i].l+cos[i].k)+1)*(cos[i].l+cos[i].k)+cos[i].m)
            {
                recent=(u/(cos[i].l+cos[i].k)+1)*(cos[i].l+cos[i].k)+cos[i].m;
                id=i;
            }
        }
        if (fg) continue;
        if (recent<=T)
        {
            fg=true;
            cos[id].yes=true;
            q.pop();
            q.push(-recent);
        }
        if (fg) continue;
        return false;
    }
    return true;
}
int main()
{
    while (scanf("%d%d",&N,&T)!=EOF)
    {
        if (N==0 && T==0) break;
        for (int i=0;i<N;i++)
        {
            scanf("%d%d%d",&cos[i].m,&cos[i].l,&cos[i].k);
        }
        int l,r;
        l=0;
        r=N;
        while (l<r)
        {
            int mid=(l+r)/2;
            if (pd(mid)) r=mid;
            else l=mid+1;
        }
        printf("%d\n",l);
    }
}

C++: #include <cstdio>
#include <iostream>
#include <string>
using namespace std;

typedef struct{
	string name;
	long s; //start
	long e; //end
}era;
	
int main(){
	while(1){
		int n, q;
		era a[1000];
		
		scanf(" %d %d", &n, &q);
		if(n==0 && q==0) break;
		
		for(int i=0; i<n; ++i){
			long le;
			cin >> a[i].name;
			scanf(" %ld %ld", &le, &a[i].e);
			a[i].s=a[i].e-le+1;	
		}
		
		for(int i=0; i<q; ++i){
			long query;
			scanf(" %ld", &query);
			
			bool found=false;
			for(int j=0; j<n; ++j){
				if(a[j].s<=query && query<=a[j].e){
					cout << a[j].name << " " << query-a[j].s+1 << endl;
					found=true;
					break;	
				}
			}
			
			if( !found ) printf("Unknown\n");
		}
		
	}
}

C++: #include <iostream>
#include <map>
using namespace std;

typedef pair<int,string> pis;

int main()
{
  while(1){
    int N, Q;
    cin >> N >> Q;
    if(N == 0 && Q == 0) break;
    map<int,pis> m;
    for(int i = 0; i < N; i++){
      string s;
      int x, y;
      cin >> s >> x >> y;
      m.insert(make_pair(y,pis(x,s)));
    }
    for(int i = 0; i < Q; i++){
      bool flag = true;
      int x;
      cin >> x;
      map<int,pis>::iterator ite;
      for(ite = m.begin(); ite != m.end(); ite++){
        if(x > ite->first - ite->second.first && x <= ite->first){
          flag = false;
          cout << ite->second.second << " " << ite->second.first - ite->first + x << endl;
          break;
        }
      }
      if(flag) cout << "Unknown" << endl;
    }
  }
}