#include <bits/stdc++.h>
using namespace std;
int main()
{
int wys, demand, ctmain=0, ctnorm=0;
scanf("%d %d", &wys, &demand);
vector<int> wina2;
int wina1[wys][wys];
for (int i=0; i<wys*(wys+1)/2; ++i) {
int pom;
scanf("%d", &pom);
wina2.push_back(pom);
wina1[ctmain][ctnorm]=pom;
++ctnorm;
if (ctnorm>ctmain) {
++ctmain;
ctnorm=0;
}
}
int lowest=2020;
for (int i=0; i<wys; ++i) {
if (wina1[i][0]<lowest) {
lowest=wina1[i][0];
}
if (wina1[i][i]<lowest) {
lowest=wina1[i][i];
}
}
ctmain=0;
ctnorm=0;
int counter=0;
bool przebito=false;
while (true) {
if (wina2[counter]<lowest) {
lowest=wina2[counter];
}
++ctnorm;
++counter;
if (counter==demand) {
przebito=true;
}
if ((przebito==true)&&(ctnorm>ctmain)) {
break;
}
if (ctnorm>ctmain) {
++ctmain;
ctnorm=0;
}
}
printf("%d", lowest);
return 0;
}
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 | #include <bits/stdc++.h> using namespace std; int main() { int wys, demand, ctmain=0, ctnorm=0; scanf("%d %d", &wys, &demand); vector<int> wina2; int wina1[wys][wys]; for (int i=0; i<wys*(wys+1)/2; ++i) { int pom; scanf("%d", &pom); wina2.push_back(pom); wina1[ctmain][ctnorm]=pom; ++ctnorm; if (ctnorm>ctmain) { ++ctmain; ctnorm=0; } } int lowest=2020; for (int i=0; i<wys; ++i) { if (wina1[i][0]<lowest) { lowest=wina1[i][0]; } if (wina1[i][i]<lowest) { lowest=wina1[i][i]; } } ctmain=0; ctnorm=0; int counter=0; bool przebito=false; while (true) { if (wina2[counter]<lowest) { lowest=wina2[counter]; } ++ctnorm; ++counter; if (counter==demand) { przebito=true; } if ((przebito==true)&&(ctnorm>ctmain)) { break; } if (ctnorm>ctmain) { ++ctmain; ctnorm=0; } } printf("%d", lowest); return 0; } |
English