Kattis Problem 'Mali'
You are storing all of the A and B inputs in sorted vectors, basically doing an insertion sort.  A few observations (two minor, one major):


The if (c == 1) special case should be eliminated.
Flag variables (founda and foundb) suck.  You would be better off writing two separate for loops.
Each time you insert a value, all values beyond the insertion point need to be shifted over to make room for the insertion.  That means that constructing as and bs takes O(N2) time altogether — which is unacceptable, since N can be very large.

However, there are only 100 possible values of A and B.  So, do a counting sort instead, building a histogram with 100 buckets.  That would be a much more efficient way to represent the same information, using O(N) time and a fixed amount of space.