Describe your issue
In this Question I submit my code and it gives an Wrong Answer
but after see what’s a difference between my output and expected output
one thing I notice , array size of input is 1000 and according to question answer can’t be exceed 1000. but in expected output 11610
Screenshot
right side expected output
Additional info
please also mention my code
#include<bits/stdc++.h>
using namespace std;
void sol(vector < long > & arr, long q) {
long start = 0;
long end = arr.size() - 1;
long loc = arr.size();
while (start <= end) {
long mid = start + (end - start) / 2;
if (arr[mid] > q) {
start = mid + 1;
} else {
end = mid - 1;
loc = mid;
}
}
long size = arr.size() - 1;
if (loc == size) {
cout << size << endl;
return;
}
start = loc;
end = size;
while (start<end) {
long req = q - arr[start];
if ( (end-start) < req)
break;
end-=req;
start++;
}
cout << start << endl;
}
bool cmp(long a, long b) {
return a > b;
}
void inp() {
long num, que;
cin >> num >> que;
vector < long > arr(num, 0);
for (long i = 0; i < num; i++)
cin >> arr[i];
sort(arr.begin(), arr.end(), cmp);
while (que--) {
long q;
cin >> q;
sol(arr, q);
}
}
int main() {
long test;
cin >> test;
while (test--) {
inp();
}
return 0;
}
