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;

int main(){
    int n;
    int q;
    while(cin>>n>>q,n){
        vector<tuple<int,int,string>> eras(n);
        for(int i=0;i<n;i++){
            string eraname;
            int eray;
            int wesy;
            cin>>eraname>>eray>>wesy;
            int startwes=wesy-eray+1;
            int endwes=wesy;
            eras[i]=make_tuple(startwes,endwes,eraname);
        }
        sort(eras.begin(),eras.end());
        for(int i=0;i<q;i++){
            int year;
            cin>>year;
            for(int j=0;j<=n;j++){
                if(eras.size()<=j){
                    cout<<"Unknown"<<endl;
                    break;
                }
                if(get<0>(eras[j])<= year && year<=get<1>(eras[j])){
                    cout<<get<2>(eras[j])<<" "<<year-get<0>(eras[j])+1<<endl;
                    break;
                }


            }



        }
    }

    return 0;
}

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

typedef struct{
  string name;
  long long start;
  long long end;
}Era;

int main()
{
  Era E[10000];
  int N,Q,s;

  while(1){
    cin>>N>>Q;
    if(N==0&&Q==0)break;
    for(int i=0;i<N;i++){
      cin>>E[i].name>>s>>E[i].end;
      E[i].start=(E[i].end-s);
    }
    for(int i=0;i<Q;i++){
      cin>>s;
      for(int j=0;j<N;j++){
	if(E[j].start<s && s<=E[j].end){
	  cout<<E[j].name<<" "<<(s-E[j].start)<<endl;
	  break;
	}
        if(j==N-1)cout<<"Unkown"<<endl;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <vector>

using namespace std;

const int N=10006, INF=0x3fffffff;

int dis[N], cost[N], pre[N];
bool vs[N], n, m;
struct data {
    int u, dis, cost;
    data() {}
    data(int _u, int _dis, int _cost) : u(_u), dis(_dis), cost(_cost) {}
};
vector <data> arc[N];
queue <int> Q;

void BFS() {
    while(!Q.empty()) Q.pop();
    for(int i=1; i<=n; i++) dis[i]=cost[i]=INF;
    memset(vs, 0, sizeof vs);
    memset(pre, -1, sizeof pre);
    cost[1]=dis[1]=0, vs[1]=1, Q.push(1);
    while(!Q.empty()) {
        int cur=Q.front();
        vs[cur]=0, Q.pop();
        int len=(int)arc[cur].size();
        for(int i=0; i<len; i++) {
            int u=arc[cur][i].u;
            int DIS=arc[cur][i].dis;
            int COST=arc[cur][i].cost;
            if(dis[u]>dis[cur]+DIS || dis[u]==dis[cur]+DIS && cost[u]>cost[cur]+COST) {
                pre[u]=cur;
                dis[u]=dis[cur]+DIS;
                cost[u]=cost[cur]+COST;
                if(!vs[u]) Q.push(u), vs[u]=1;
            }
        }
    }
}

int main() {
    freopen("/home/lovezzt/桌面/in.txt", "r", stdin);
    while(scanf("%d%d", &n, &m), n!=0 || m!=0) {
        for(int i=1; i<=n; i++) arc[i].clear();
        for(int i=0, a, b, c, d; i<m; i++) {
            scanf("%d%d%d%d", &a, &b, &c, &d);
            arc[a].push_back(data(b, c, d));
            arc[b].push_back(data(a, c, d));
        }
        BFS();
        int sum=0;
        memset(vs, 0, sizeof vs);
        for(int i=1; i<=n; i++) if(pre[i]!=-1) vs[pre[i]]=1;
        for(int i=1; i<=n; i++) if(!vs[i]) sum+=cost[i];
        printf("%d\n", sum);
    }
    return 0;
}

C++: #include<stdio.h>
char str[1000][20];
int c[1000];
int d[1000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%s%d%d",str[i],c+i,d+i);
		for(int i=0;i<b;i++){
			int e;
			scanf("%d",&e);
			bool ok=false;
			for(int j=0;j<a;j++){
				if(1+d[j]-c[j]<=e&&e<=d[j]){
					printf("%s %d\n",str[j],e-d[j]+c[j]);
					ok=true;
					break;
				}
			}
			if(!ok)printf("Unknown\n");
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

class Range {
public:
    int start, end;
    Range() {}
    Range(int s, int e) {
	start = s;
	end = e;
    }
};

signed main() {
    int N, Q;
    while (cin >> N >> Q) {
	if (N == 0) break;

	map<string, Range> infos;
	rep(i, N) {
	    string name;
	    int a, b;
	    cin >> name >> a >> b;

	    if (infos.find(name) == infos.end()) {
		infos[name] = Range(b - a + 1, b);
	    } else {
		infos[name].end = max(infos[name].end, b);
	    }
	}

	rep(i, Q) {
	    int a;
	    cin >> a;

	    bool output = false;
	    for (auto it = infos.begin(); it != infos.end(); it++) {
		auto &info = (*it).second;
		if (info.start <= a && info.end >= a) {
		    cout << (*it).first << ' ' << (a - info.start + 1) << endl;
		    output = true;
		    break;
		}
	    }
	    if (!output) {
		cout << "Unknown" << endl;
	    }
	}
    }

    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct data
{
    char name[16];
    long long y,wy;
}d[1001];

long long year,temp;
int main()
{
    int n,m,i,j,k,flag;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==0&&m==0)break;
        for(i=0;i<n;i++)
        {
            scanf("%s %lld %lld",d[i].name,&d[i].y,&d[i].wy);
        }
        /*for(i=0;i<n;i++)
        {printf("%s %lld ",d[i].name,d[i].y);
            printf("%lld\n",d[i].wy);}*/
        for(j=0;j<m;j++)
        {
            scanf("%lld",&year);
            flag=0,temp=0;
            for(i=0;i<n;i++)
            {
                if((d[i].wy>=year)&&((d[i].wy-year)<d[i].y))
                {
                    flag=1;
                    temp=d[i].y-(d[i].wy-year);
                    k=i;
                    break;
                }
            }
            if(flag)
                printf("%s %lld\n",d[k].name,temp);
            else
                printf("Unknown\n");
        }
    }
    return 0;
}