I have a 2D vector v (all values are positive and the 2D matrix is a square matrix) and a given value k. For e.g.,
v={
{2,1},
{3,4}
}
k = 3
I want to find and store all those combinations of i, j such that
arr[i] + arr[j] = k, or
arr[i] = k, or
arr[j] = k
For example v[0][0] + v[0][1] = 3 & v[1][0] = 3. I want to store the pairs in an array like this std::vector<std::vector<std::pair<int, int>>>.
Sample input:
v={
{2,1},
{3,4}
}
k = 3
Sample output:
{{(0,0),(0,1)}, {(1,0)}}
Individual parts I worked by;
#include<iostream>
#include<vector>
int main(){
using namespace std;
vector<vector<int>>v={{2,1},{3,4}};
vector<pair<int,int>>k;
int size=v.size();
for(size_t i=0;i<size;i++){
for(size_t j=0;j<size;j++){
if(v[i][j]==3){
k.push_back(make_pair(i,j));
}
}
}
}
Edit link for actual questions which I perceived and tried to solve in the above mentioned way.