Suppose the input data is an array, and input[m] stores m numbers.
int exist[n]= { 0 }; //Indicates whether the number in 1-n appears.
int I = 0;
for(I = 0; I & ltm;; i++) {
int number = input[I];
There exists [number-1] = 1
}
If a number a appears, then exist[a- 1] is 1, otherwise it is 0.
Sum to get the result.
The second problem is linear programming. You didn't give the photo.