Some quick thoughts:
In
gfg::satisfiable()
, vector
b doesn't get re-ordered, so you don't need to sort each time through the
while
loop. You do decrement elemnts
0..k elements of
b, but that won't change the sort order.
push_back()
checks the current allocation of the vector and possibly re-allocates each time. Pre allocating the vector, and using direct element access will reduce the time taken to set up the vector:
vector<int> a(r);
for(int i = 0; i < r; ++i)
cin >> a[i];
This will help greatly if the number of inputs is large;
If possible read the entire input file in one go, and then use string processing to parse it. The input format is probably fairly simple, so it should be possible to write a parser that doesn't use the (possibly slow)
iostream
facility.
If you can't read the entire input file in one go, maybe you can use
getline()
to read some, or all, of the elements of the vector, then parse them out.