-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10487-1.cpp
45 lines (43 loc) · 825 Bytes
/
10487-1.cpp
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
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#define foi( i , n , k) for( int i = n ; i < k ; i++)
using namespace std;
int main()
{
int n,c=0;
while(scanf("%d",&n)!=EOF && n!= 0)
{
vector<int> v(n),vv;
foi( i , 0 , n )
scanf("%d",&v[i]);
foi( i , 0 , n )
foi( j , i+1 , n)
vv.push_back(v[i]+v[j]);
int q;
scanf("%d",&q);
printf("Case %d:\n",++c);
foi( i , 0 , q )
{
int m;
scanf("%d",&m);
int men,num=0;
foi( j , 0 , vv.size() )
{
if( j == 0)
{
num=vv[j];
men=abs(num-m);
}
else if( men > abs(vv[j]-m))
{
men=abs(vv[j]-m);
num=vv[j];
}
}
printf("Closest sum to %d is %d.\n",m,num);
}
}
return 0;
}