Q:

MAX value of matrix and saving indexes in the same loop

I get a NxM sized matrix and I have to find the max value, the number of max values and the lines that contain it.
I tired using three for{for{}} loops, but it took too long. This method seems to work for small inputs, but when I try it with a 1000x1000 matrix, it finishes before it even takes all the input. 
I realise this may be too much of a noob question, but I couldn't find anything else.
Here's my code:
#include <iostream>
using namespace std;

int main()
{
    int n, m;
    int crnt{-51}, cnt{0};
    cin >> n >> m;
    int vekt[m];
    int lines[n];
    int inp;
    for(int i=0; i<n; i++)
    {
        for(int p=0; p<m; p++)
        {
            cin >> vekt[p];
        }
        for(int j=0; j<m; j++)
        {
            if(vekt[j] == crnt)
            {
                lines[cnt] = i + 1;
                cnt += 1;
            }
            if(vekt[j] > crnt)
            {
                crnt = vekt[j];
                lines[0] = i + 1;
                cnt = 1;
            }
        }
    }
    cout << cnt;
    for(int i=0; i<cnt; i++)
    {
        cout << " " << lines[i]; 
    }
    return 0;
}

EDIT : not using vector or [n] was just easier... I simply saved it to a variable and used a bool:
int main()
{
    int n, m;
    int crnt{-51}, cnt{0};
    cin >> n >> m;
    int vekt[m];
    int lines[n];
    int inp;
    bool inLine;
    inLine = false;
    for(int i=0; i<n; i++)
    {

        inLine = false;
        for(int j=0; j<m; j++)
        {
            cin >> inp;
            if(inp == crnt && inLine == false)
            {
                lines[cnt] = i + 1;    
                cnt += 1;
                inLine = true;    
            }
            if(inp > crnt)
            {
                crnt = inp;
                lines[0] = i + 1;
                cnt = 1;
            }
        }
    }
    cout << cnt;
    for(int i=0; i<cnt; i++)
    {
        cout << " " << lines[i]; 
    }
    return 0;
}

This cut the time by enough so that I went under the limit.

A:

int vekt[m]; is not standard C++, it is a variable length array (which some compilers allow as extension). Use std::vector instead.
That would also fix the bug you currently have: If cnt >= n (i.e. if you find more maxima than the matrix has lines), you will go out of bounds of lines and your program will most likely crash (although anything could happen), which is more likely to happen with larger matrices.
You can do this instead:

Declaration and initialization:
std::vector<int> linesWithMaxima;
When you find another value equal to the current maximum:
linesWithMaxima.push_back(i+1);
When you find a new maximum (larger than current):
linesWithMaxima.clear();
linesWithMaxima.push_back(i+1);

Note that this will list a line with multiple (identical) maxima multiple times. If you want to avoid duplicates, you can either check that you have not already added the current line (linesWithMaxima.back() != i+1) or use std::sort, std::unique and std::vector::erase.
Other than that your code looks fine. I would recommend naming the loop indices better (line instead of i etc.) and possibly merging the p and j loop because separating them seems to have no purpose. And if you want the most negative integer, use std::numeric_limits<int>::lowest().

