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 <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int N, Q;

    while (cin >> N >> Q, N || Q) {
        cerr << N << " " << Q << endl;
        vector<pair<int, string> > memo;

        for (int i = 0; i < N; i++) {
            string s;
            int ey, wy;

            cin >> s >> ey >> wy;
            cerr << s << " " << ey << " " << wy << endl;
            memo.push_back(make_pair(wy - ey, s));
        }
        sort(memo.begin(), memo.end());


        for (int i = 0; i < Q; i++) {
            int q;

            cin >> q;
            cerr << q << endl;
            bool flag = false;
            vector<pair<int, string> >::iterator it = memo.begin();

            while (it != memo.end()) {
                if ((*it).first > q && memo.size() > 1) {
                    advance(it, -1);
                    flag = true;
                    cout << (*it).second << " " << q - (*it).first << endl;
                    break;
                }

                it++;
            }
            if (!flag)
                cout << "Unknown" << endl;
        }
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
int N,Q;
signed main(){
  while(cin >> N >> Q && (N!=0 || Q!=0)){
    map<int,string> start;
    map<string,int> finish;
    rep(i,N){
      string Eraname;
      int Erabaseyear,Westernyear;
      cin >> Eraname >> Erabaseyear >> Westernyear;
      start[Westernyear-(Erabaseyear-1)]=Eraname;
      finish[Eraname]=Westernyear;
    }
    rep(i,Q){
      int q,label=0;
      cin >> q;
      for(auto p=start.begin();p!=start.end();p++){
        if(p->first<=q){
          string e=start[p->first];
          if(finish[e]>=q){
            cout << e  << " " << q-p->first+1<< endl;
            label++;
            break;
          }
        }
      }
      if(label==0) cout << "Unknown" << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>

using namespace std;

vector<int> cn[2005];
bool flag[2005], used[2005];
int linked[2005];

bool find(int u) {
	if(flag[u]) {
		return 0;
	}
	flag[u] = 1;
	for(int i = 0; i < (int)cn[u].size(); i++) {
		int id = cn[u][i];
		if(!linked[id] || find(linked[id])) {
				linked[id] = u;
				return 1;
		}
	}
	return 0;
}

int max_match(int n) {
	int ans = 0;
	bool solved;
	memset(used, 0, sizeof(used));
	memset(linked, 0, sizeof(linked));
	while(1) {
		solved = 0;
		for(int i = 1; i <= n; i++) {
			memset(flag, 0, sizeof(flag));
			if(!used[i] && find(i)) {
				used[i] = 1;
				solved = 1;
				ans++;
				break;
			}
		}
		if(!solved) {
			return ans;
		}
	}
}

int mp[110][110], n, m, L;
int p[110], t[110];

int main() {
	while(~scanf("%d%d%d", &n, &m, &L)) {
		memset(mp, -1, sizeof(mp));
		for(int i = 1; i <= m; i++) {
			int u, v, c;
			scanf("%d%d%d", &u, &v, &c);
			if(mp[u][v] == -1) {
				mp[u][v] = c;
			}else {
				mp[u][v] = min(mp[u][v], c);
			}
		}
		for(int i = 1; i <= L; i++) {
			scanf("%d%d", &p[i], &t[i]);
		}
		for(int i = 1; i <= 2*L; i++) {
			cn[i].clear();
		}
		for(int i = 1; i <= L; i++) {
			for(int j = 1; j <= L; j++) {
				if(mp[i][j] == -1) {
					continue;
				}
				if(i == j || p[i] == p[j]) {
					continue;
				}
				if(mp[p[i]][p[j]] + t[p[i]] <= t[p[j]]) {
					cn[i+n].push_back(j);
				}
			}
		}
		for(int i = 1; i <= L; i++) {
			cn[i].push_back(i + n);
		}
		int ans = n - max_match(n);
		printf("%d\n", ans);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

const int SZ=1005;
int l[SZ],r[SZ];
string name[SZ];

signed main()
{   
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,q;
    while(cin>>n>>q,n)
    {
        REP(i,n){
            int a;
            cin>>name[i]>>a>>r[i];
            l[i]=r[i]-a;
        }
        REP(i,q){
            int year; cin>>year;
            REP(j,n){
                if(l[i]<year && year<=r[i]){
                    cout<<name[i]<<" "<<year-l[i]<<endl;
                    goto g;
                }
            }
            cout<<"Unknown"<<endl;
        g:;
        }

    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <string>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;

int main () {
    int N, Q;
    while (cin >> N >> Q, N + Q) {
        vector<string> name(N);
        vector<pii> len(N);
        REP (i, 0, N) {
            cin >> name[i];
            int f, e;
            cin >> f >> e;
            len[i].first = e - f + 1;
            len[i].second = e;
        }
        REP (i, 0, Q) {
            int q;
            cin >> q;
            int cnt = 0;
            string ans = "";
            int l = 0;
            REP (j, 0, N) {
                if (len[j].first <= q && q <= len[j].second) {
                    cnt++;
                    ans = name[j];
                    l = q - len[j].first + 1;
                }
            }
            if (cnt == 1) {
                cout << ans << " " << l << endl;
            } else {
                cout << "UnKnown" << endl;                
            }

        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

struct P{
    int begin;
    int end;
    string str;

    P(int b, int e, string s){
        begin = b;
        end = e;
        str = s;
    }

    bool operator < (const P& p)const{
        return begin < p.begin;
    }
};

int main(void){
    int N, Q;
    while(cin >> N >> Q, N | Q){
    vector< P > v;
    for(int i = 0; i < N; i++){
        string str; int base, east;
        cin >> str >> base >> east;
        v.push_back( P(east - base + 1, east, str) );
    }
    sort(v.begin(), v.end());

    for(int i = 0; i < Q; i++){
        int y; cin >> y;
        int ans = -1;
        string str;
        for(int j = v.size() - 1; j >= 0; j--){
            if(v[j].begin <= y && y <= v[j].end){
                ans = y - v[j].begin + 1;
                str = v[j].str;
                break;
            }
        }
        if(ans == -1) cout << "Unknown" << endl;
        else cout << str << " " << ans << endl;
    }
    }
    return 0;
}