You are viewing a single comment's thread. Return to all comments →
I saw this following code by Isming , so can someone explain the logic behind max(0, q[i] - 2) in nested for loop?
void calc(vector<int> q) { int ans = 0; for (int i = q.size() - 1; i >= 0; i--) { if (q[i] - (i + 1) > 2) { cout << "Too chaotic" << endl; return; } for (int j = max(0, q[i] - 2); j < i; j++) if (q[j] > q[i]) ans++; } cout << ans << endl; }
Seems like cookies are disabled on this browser, please enable them to open this website
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
I saw this following code by Isming , so can someone explain the logic behind max(0, q[i] - 2) in nested for loop?