#include <iostream>
#include <string>
#include <vector>
using namespace std;
size_t split(const std::string &txt, std::vector<std::string> &strs, char ch)
{
size_t pos = txt.find( ch );
size_t initialPos = 0;
strs.clear();
// Decompose statement
while( pos != std::string::npos ) {
strs.push_back( txt.substr( initialPos, pos - initialPos ) );
initialPos = pos + 1;
pos = txt.find( ch, initialPos );
}
// Add the last one
strs.push_back( txt.substr( initialPos, std::min( pos, txt.size() ) - initialPos + 1 ) );
return strs.size();
}
int main(){
string rawInput;
vector<string> years;
getline(cin, rawInput);
split( rawInput, years, ' ' );
int n = stoi(years.at(0));
int k = stoi(years.at(1));
years.clear();
if(n < 1 || n > 2000)
return -1;
if(k < 1 || k > n*(n + 1)/2)
return -1;
int tab[n][n*(n+1)/2];
for(int i = 0; i < n; i++){
getline( cin, rawInput);
split( rawInput, years, ' ' );
for(int j = 0; j <= i; j++){
if((stoi(years.at(j)) < 1) || (stoi(years.at(j)) > 2019))
return -1;
tab[i][j] = stoi(years.at(j));
}
years.clear();
}
int bottles = k;
int row = 1;
while(bottles > row){
bottles -= row;
row++;
}
row--;
int year = tab[row][0];
for(int i = 0; i < (row+1); i++){
if(tab[row][i] < year)
year = tab[row][i];
}
std::cout << year;
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 55 56 57 58 59 60 61 62 63 | #include <iostream> #include <string> #include <vector> using namespace std; size_t split(const std::string &txt, std::vector<std::string> &strs, char ch) { size_t pos = txt.find( ch ); size_t initialPos = 0; strs.clear(); // Decompose statement while( pos != std::string::npos ) { strs.push_back( txt.substr( initialPos, pos - initialPos ) ); initialPos = pos + 1; pos = txt.find( ch, initialPos ); } // Add the last one strs.push_back( txt.substr( initialPos, std::min( pos, txt.size() ) - initialPos + 1 ) ); return strs.size(); } int main(){ string rawInput; vector<string> years; getline(cin, rawInput); split( rawInput, years, ' ' ); int n = stoi(years.at(0)); int k = stoi(years.at(1)); years.clear(); if(n < 1 || n > 2000) return -1; if(k < 1 || k > n*(n + 1)/2) return -1; int tab[n][n*(n+1)/2]; for(int i = 0; i < n; i++){ getline( cin, rawInput); split( rawInput, years, ' ' ); for(int j = 0; j <= i; j++){ if((stoi(years.at(j)) < 1) || (stoi(years.at(j)) > 2019)) return -1; tab[i][j] = stoi(years.at(j)); } years.clear(); } int bottles = k; int row = 1; while(bottles > row){ bottles -= row; row++; } row--; int year = tab[row][0]; for(int i = 0; i < (row+1); i++){ if(tab[row][i] < year) year = tab[row][i]; } std::cout << year; return 0; } |
English