#include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef LOCALHACKER #define LOG std::cerr #else #define LOG if(false) std::cerr #endif class IOHandler { public: IOHandler(std::istream &is, std::ostream &os) : input(is), output(os) { } std::istream &input; std::ostream &output; }; void run(IOHandler &io) { int n; io.input >> n; std::vector a(n); for (ssize_t i = 0; i < n ; ++i) { int ai; io.input >> ai; a[i] = ai; } std::sort(a.begin(), a.end()); int max = 0; int last = a[0]; int seqStart = 0; int seqEnd = 0; for (ssize_t i = 1; i < n ; ++i) { if (a[i] - last <= 1) { LOG << i << " " << a[i] - last << " " << a[i] << " " << last; seqEnd = i; } else { if (seqEnd - seqStart + 1 > max) { max = seqEnd - seqStart + 1; } last = a[i]; seqStart = i; seqEnd = i; }; } if (seqEnd - seqStart + 1 > max) { max = seqEnd - seqStart + 1; } io.output << max << std::endl; } void runInteractive() { IOHandler ioh(std::cin, std::cout); run(ioh); } bool endsWith(const std::string &str, const std::string &pattern) { return str.size() >= pattern.size() && str.compare(str.size() - pattern.size(), pattern.size(), pattern) == 0; } void runTests(const std::string &path, std::set ignores = {}) { DIR *pDIR; struct dirent *entry; std::map testCases; if( pDIR=opendir(path.c_str()) ){ while(entry = readdir(pDIR)){ if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 ){ std::string filenameAnswer = entry->d_name; if (endsWith(filenameAnswer, ".answer")) { std::string filename = filenameAnswer; testCases.insert({filename.erase(filename.size() - 7, 7), filenameAnswer}); } } } closedir(pDIR); } for (auto &it : testCases) { if (ignores.count(it.first) == 0) { std::cout << "Running " << it.first << std::endl; std::stringstream filename; filename << path << "/" << it.second; std::ifstream answer(filename.str()); std::string expectedResult((std::istreambuf_iterator(answer)), std::istreambuf_iterator()); answer.close(); filename.str(""); filename << path << "/" << it.first; std::ifstream ifs(filename.str()); std::stringstream output; IOHandler ioh(ifs, output); run(ioh); ifs.close(); std::string result = output.str(); expectedResult.erase(std::remove(expectedResult.begin(), expectedResult.end(), ' '), expectedResult.end()); expectedResult.erase(std::remove(expectedResult.begin(), expectedResult.end(), '\n'), expectedResult.end()); result.erase(std::remove(result.begin(), result.end(), ' '), result.end()); result.erase(std::remove(result.begin(), result.end(), '\n'), result.end()); bool correctResult = (expectedResult == result); std::cout << it.second << " " << (correctResult ? "PASS" : "FAIL") << std::endl; if (!correctResult) { std::cout << "EXPECTED: " << expectedResult << std::endl; std::cout << "GOT : " << result << std::endl; } } } } int main() { #ifdef LOCALHACKER runTests("/home/dirb/gitrepos/101hack44/problem1"); #else runInteractive(); #endif return 0; }