CSES - HIIT Open 2017 - Results
Submission details
Task:Contest
Sender:Proudly div 2
Submission time:2017-05-27 15:56:33 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:13:32: error: 'max1' was not declared in this scope
  cout << "1 1" << endl; cin >> max1;
                                ^
input/code.cpp:14:36: error: 'min1' was not declared in this scope
  cout << "1 " << n << endl; cin >> min1;
                                    ^
input/code.cpp:16:32: error: 'max2' was not declared in this scope
  cout << "2 1" << endl; cin >> max2;
                                ^
input/code.cpp:17:36: error: 'min2' was not declared in this scope
  cout << "2 " << n << endl; cin >> min2;
                                    ^

Code

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;

	int a1 = 1, a2 = 1, l1 = n, l2 = n, v1, v2;

	cout << "1 1" << endl; cin >> max1;
	cout << "1 " << n << endl; cin >> min1;

	cout << "2 1" << endl; cin >> max2;
	cout << "2 " << n << endl; cin >> min2;

	if(min1 > max2) {
		if(n > k) {
			cout << "1 " << k; cin >> k;
			cout << "3 " << k;
			return 0;
		} else {
			cout << "2 " << k-n; cin >> k;
			cout << "3 " << k;
			return 0;
		}
	} else if(min2 > max1) {
		if(n > k) {
			cout << "2 " << k; cin >> k;
			cout << "3 " << k;
			return 0;
		} else {
			cout << "1 " << k-n; cin >> k;
			cout << "3 " << k;
			return 0;
		}
	}

	while(l1-a1 > 8 || l2-a2 > 8) {
		int i1 = (a1+l1)/2, i2 = (a2+l2)/2;
		cout << "1 " << i1 << endl; cin >> v1;
                cout << "2 " << i2 << endl; cin >> v2;

		if(i1 + i2 < k) {
			if(v1 > v2) {
				l2 = i2;
			} else {
				l1 = i1;
			}
		} else {
			if(v1 > v2) {
				a1 = i1;
			} else {
				a2 = i2;
			}
		}

		//if(v1 > v2) {
		//	a1 = i1;
		//	l2 = i2;
		//} else {
		//	a2 = i2;
		//	l1 = i1;
		//}
	}

	vector<int> v;
	
	for(int i=a1; i<=l1; i++) {
		cout << "1 " << i << endl;
		cin >> v1; v.push_back(v1);
	}
	for(int i=a2; i<=l2; i++) {
		cout << "2 " << i << endl;
		cin >> v2; v.push_back(v2);
	}

	sort(v.rbegin(), v.rend());

	cout << "3 " << v[k - a1 - a2 + 1] << endl;
}