int minMoves(vectorarr, int n, int k) { // Sort the array sort(arr.begin(), arr.end()); int i = 0, j = n - 1; int moves = 0; // Two pointers approach while (i <= j) { // If the lightest and heaviest together are within the limit, move both if (arr[i] + arr[j] <= k) { i++; // move the lighter object } // Move the heavier object (j--) j--; // Count one move moves++; } return moves; }