Editorial for Add Array
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
#include <iostream> #include <vector> using namespace std; int ask(int u, int v) { cout << "? " << u << " " << v << endl; int res; cin >> res; return res; } int main() { int n; if (!(cin >> n)) return 0; int total_elements = 0; vector<bool> removed(2005, false); for (int i = 0; i < n; i++) { int x; cin >> x; total_elements += x; int current_min = -1; for (int j = 1; j <= total_elements; j++) { if (removed[j]) continue; if (current_min == -1) { current_min = j; } else { int cmp = ask(current_min, j); if (cmp == 1) { // a[current_min] > a[j] current_min = j; } } } cout << "! " << current_min << " 1" << endl; removed[current_min] = true; } return 0; }
Comments