# AtCoder Beginner Contest 163 解题报告

A - Circle Pond
Print the circumference of a circle of radius R.
1 ≤ R ≤ 100

``````double r;
int main()
{
cin >> r;
cout << 2 * acos(-1) * r;
return 0;
}``````

B - Homework
Takahashi has N days of summer vacation. His teacher gave him M summer assignments. It will take Ai days for him to do the i-th assignment. He cannot do multiple assignments on the same day, or hang out on a day he does an assignment. What is the maximum number of days Takahashi can hang out during the vacation if he finishes all the assignments during this vacation? If Takahashi cannot finish all the assignments during the vacation, print -1 instead.
1 ≤ N ≤ 106
1 ≤ M ≤ 104
1 ≤ Ai ≤ 104

``````int n, m, a, sum;
int main()
{
for(int i = 1; i <= m; ++i)
{
sum += a;
}
if(sum > n) printf("-1");
else printf("%d", n - sum);
return 0;
}``````

C - management
A company has N members, who are assigned ID numbers 1,...,N. Every member, except the member numbered 1, has exactly one immediate boss with a smaller ID number. When a person X is the immediate boss of a person Y, the person Y is said to be an immediate subordinate of the person X. You are given the information that the immediate boss of the member numbered i is the member numbered Ai. For each member, find how many immediate subordinates it has.
2 ≤ N ≤ 2 × 105
1 ≤ Ai < i

``````int n, ans;
int main()
{
for (int i = 2, t; i <= n; ++i)
{
++ans[t];
}
for (register int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
return 0;
}``````

D - Sum of Large Numbers
We have N+1 integers: 10100, 10100+1,..., 10100+N. We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (109+7).
1 ≤ N ≤ 2 × 105
1 ≤ K ≤ N + 1

``````int n,k;
long long ans,sum;
int main()
{
for (int i=1;i<=n;++i) sum[i]=sum[i-1]+i;
while(k<=n+1)
{
ans+=sum[n]-sum[n-k]-sum[k-1]+1;
ans%=1000000007;
++k;
}
printf("%lld",ans);
return 0;
}``````

E - Active Infants
There are N children standing in a line from left to right. The activeness of the i-th child from the left is Ai. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns Ax × |x−y| happiness points. Find the maximum total happiness points the children can earn.
1 ≤ N ≤ 2000
1 ≤ Ai ≤ 109