1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main()
{
    int n;
    int k;
    string arguments;
    string argumentsChar="";
    bool nextArg=false;

        getline(cin, arguments);
        arguments+=" ";
        int sizearguments=arguments.length();

        for(int i=0;i<sizearguments;i++)
        {
            char s=arguments[i];
            if(s>='0'&&s<='9')
            {
                argumentsChar+=s;
            }
            else if(argumentsChar!=""&&nextArg==false)
            {
                n=atoi(argumentsChar.c_str());
                argumentsChar="";
                nextArg=true;
            }
            else if(argumentsChar!=""&&nextArg==true)
            {
                k=atoi(argumentsChar.c_str());
                argumentsChar="";
            }
        }

    int bottles = n*(n+1)/2*3;
    int myArray[n][n];
    int dane[bottles+bottles+bottles];
    int x=0;
    string line;
    string numberChar="";
    for(int i=0;i<n;i++)
    {
        int j=0;
        getline(cin, line);
        line+=" ";
        int sizelinea=line.length();
        for(int l=0;l<sizelinea;l++)
        {
            char c=line[l];
            if(c>='0'&&c<='9')
            {
                numberChar+=c;
            }

            else if(numberChar!="")
            {
                myArray[i][j] = atoi(numberChar.c_str());
                numberChar="";
                j++;
            }
        }
    }

	for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            dane[x]=myArray[i][j];
            dane[x+1]= i;
            dane[x+2]= j;
            x+=3;
        }
	}

	for(int i=0;i<x;i++){
        for(int j=3;j<x-i;j+=3){
            if(dane[j-3]>dane[j]){
                swap(dane[j], dane[j-3]);
                swap(dane[j+1], dane[j-2]);
                swap(dane[j+2], dane[j-1]);
            }
        }
    }

	int out=2020;
    for(int i=0;i<x;i+=3){
        int skok;
        skok= (dane[i+2]+1)*(dane[i+1]-dane[i+2]+1);
        if(dane[i]<out&&skok<=k){
            out=dane[i];
            break;
            }


    }
    cout << out;
    return 0;
}