forked from AllAlgorithms/cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchefres.cpp
More file actions
48 lines (44 loc) · 899 Bytes
/
chefres.cpp
File metadata and controls
48 lines (44 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,m;
cin>>t;
while(t--)
{
cin>>n>>m;
int a[n],b[n],c[n]={0},f;
for(int i=0;i<n;i++)
{
cin>>a[i]>>b[i];
}
for(int j=0;j<m;j++)
{
cin>>f;
int flag1=0;
for(int k=0;k<n;k++)
{
if(f>=a[k]&&f<b[k])
{ cout<<0<<"\n";
flag1=1;
break;}
else
{
c[k]=a[k]-f;
}
}
if(flag1==0)
{
int flag=0;
sort(c,c+n);
for(int k=0;k<n;k++)
if(c[k]>=0)
{cout<<c[k]<<"\n";flag=1;
break;}
if(flag==0)
cout<<-1;
}
}
}
}