Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Jakub Jakubowski
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int n,x,j,najsuma=2000001,zero,suma,rozm,xx,ok;
- bool da_sie(int tabli[][3],int xx,int nt)
- {
- for (int i=3;i<nt;++i)
- if (tabli[i][2]!=xx)
- if (tabli[i][2]!=-xx)
- return 0;
- return 1;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- vector <int> numerki;
- vector <int> dworzec (1000001,0);
- vector <int> lotnisko (1000001,0);
- cin >> n;
- int tab[n][3];
- if (n==3)
- {
- cin >> tab[0][0]>>tab[0][1];
- cout << "TAK"<<endl;
- cout << 1 << " "<< 2 << " "<< tab[0][0]<<endl;
- cout << 2 << " "<< 3 << " "<< tab[0][1];
- return 0;
- }
- vector <int> srodek ;
- vector <int> roznica;
- for (int i=2;i<n;++i)
- cin >> tab[i][0];
- for (int i=2;i<n;++i)
- {
- cin >> tab[i][1];
- tab[i][2]=tab[i][0]-tab[i][1];
- suma=tab[i][0]+tab[i][1];
- if (suma==najsuma)
- {srodek.push_back(tab[i][2]);numerki.push_back(i);}
- if (suma<najsuma)
- {
- srodek.clear();
- numerki.clear();
- najsuma=suma;
- srodek.push_back(tab[i][2]);
- numerki.push_back(i);
- }
- if (tab[i][2]>0)
- if (dworzec[tab[i][2]]==0)
- {dworzec[tab[i][2]]=-1;
- roznica.push_back(tab[i][2]);}
- else if (tab[i][2]<0)
- if (lotnisko[-tab[i][2]]==0)
- {lotnisko[-tab[i][2]]=-1;
- roznica.push_back(tab[i][2]);}
- else
- {
- if (dworzec [0]==0)
- {
- {dworzec[0]=1;
- roznica.push_back(0);}
- }
- if (tab[i][1]<zero)
- zero=suma;
- }
- }
- xx=tab[2][2];
- rozm=srodek.size();
- if (xx!=0)
- if (da_sie(tab,xx,n)==1)
- {
- cout << "TAK"<<endl;
- cout << 1 << " "<< n << " " << xx<<endl;
- for (int i=2;i<n;++i)
- if (tab[i][2]>0)
- cout << i << " "<< n << " " << tab[i][1]<<endl;
- else
- cout << i << " "<< 1 << " " << tab[i][0]<<endl;
- return 0;
- }
- if (zero!=0)
- if (zero!=najsuma)
- {
- cout << "NIE";
- return 0;
- }
- if (roznica.size()>rozm+2)
- {
- cout << "NIE";
- return 0;
- }
- dworzec[najsuma]=n;
- lotnisko[najsuma]=1;
- for (int i=0;i<rozm;++i)
- {
- if (srodek[i]>=0)
- dworzec[srodek[i]]=numerki[i];
- else
- lotnisko[-srodek[i]]=numerki[i];
- }
- for (int i=0;i<roznica.size();++i)
- {
- if (roznica[i]>=0)
- {
- if (dworzec[roznica[i]]==-1)
- {
- cout << "NIE";
- return 0;
- }
- }
- else
- if (lotnisko[roznica[i]]==-1)
- {
- cout << "NIE";
- return 0;
- }
- }
- vector <int> a (rozm);
- vector <int> xd (1000001);
- for (int i=0;i<rozm;++i)
- if (srodek[i]>=0)
- {a[i] = tab[dworzec[srodek[i]]][0];
- xd[a[i]]=dworzec[srodek[i]];}
- else
- {a[i] = tab[lotnisko[-srodek[i]]][0];
- xd[a[i]]=lotnisko[-srodek[i]];}
- sort(a.begin(),a.end());
- for (int i=1;i<rozm;++i)
- if (a[i] - a[i-1]==0)
- {cout << "NIE";
- return 0;}
- cout << "TAK"<<endl;
- cout << 1 << " "<< xd[a[0]]<< " "<< a[0]<<endl;
- tab [xd[a[0]]][2] = -1;
- for (int i=1;i<rozm-1;++i)
- {
- cout << xd[a[i-1]] << " "<<xd[a[i]] << " " << a[i] - a[i-1]<<endl;
- tab[xd[a[i]]][2]=-1;
- }
- if (rozm>1)
- {cout << xd[a[rozm-2]] << " "<<xd[a[rozm-1]] << " " << a[rozm-1] - a[rozm-2]<<endl<<xd[a[rozm-1]]<< " "<<n<<" "<<tab[xd[a[rozm-1]]][1]<<endl;
- tab[xd[a[rozm-1]]][2]=-1;}
- else
- cout << xd[a[0]] << " "<< n << " "<<tab[xd[a[0]]][1]<<endl;
- for (int i=2;i<n;++i)
- {
- if (tab[i][2]!=-1)
- {
- if (tab[i][2]==najsuma)
- cout << n << " "<< i<< " " << tab[i][1]<<endl;
- else if (tab[i][2]==-najsuma)
- cout << 1 << " "<< i<< " " << tab[i][0]<<endl;
- else if (tab[i][2]>=0)
- {
- cout << dworzec[tab[i][2]] << " " << i << " " << tab[i][1] - tab[dworzec[tab[i][2]]][1]<<endl;
- }
- else
- {
- cout << lotnisko[-tab[i][2]] << " " << i << " " << tab[i][0] - tab[lotnisko[-tab[i][2]]][0]<<endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement