Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using pii=pair<int,int>;
- int main(){
- int n,p;
- scanf("%d%d",&n,&p);
- vector <int> g[n+1];
- map < int , vector<int> > mp;
- for(int i=1;i<=n;i++){
- for(int j=0;j<p;j++){
- int x;
- scanf("%d",&x);
- g[i].push_back(x);
- if(j==0) mp[x].push_back(i);
- }
- }
- int product[p];
- for(int j=0;j<p;j++) {
- scanf("%d",&product[j]);
- }
- bool found;
- for(auto i:mp[product[0]]){
- found=true;
- for(int j=0;j<p;j++){
- if(product[j]!=g[i][j]) {
- found=false;
- break;
- }
- }
- if(found){
- printf("%d",i);
- return 0;
- }
- }
- for(int k=1;k<=n;k++){
- int x;
- x=product[0]-g[k][0];
- for(auto i:mp[x]){
- found=true;
- for(int j=0;j<p;j++) {
- if(g[k][j]+g[i][j]!=product[j]){
- found=false;
- break;
- }
- }
- if(found && k!=i) {
- if(k<i) printf("%d %d",k,i);
- else printf("%d %d",i,k);
- return 0;
- }
- }
- }
- printf("NO");
- return 0;
- }
Add Comment
Please, Sign In to add comment