Răspuns:
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("parimpar2.in");
ofstream g("parimpar2.out");
int main()
{
long i,p,x,ok1,ok2,par,impar;
f>>i>>p;
ok1=0;
ok2=0;
while(f>>x){
if(x%2==0){
ok1++;
if(ok1==p)
par=x;}
if(x%2==1){
ok2++;
if(ok2==i)
impar=x;}
}
if(ok1<p || ok2<i)
g<<"Nu exista";
else
g<<par<<" "<<impar;
return 0;
}
Explicație: