Official
B - Bird Watching Editorial by en_translator
Original proposer: admin
By utilizing for loops, the problem can be solved by managing the following information in the manner of bucket sort:
- \(S_i\), the sum of sizes of birds of kind \(i\)
- \(C_i\), the number of birds of kinds \(i\)
For each kind, the answer can be found as \(S_i/C_i\).
Make sure to print a sufficient number of digits.
Sample code (C++):
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
vector<int> S(m+1,0);
vector<int> C(m+1,0);
for(int i=0;i<n;i++){
int a,b;
cin >> a >> b;
S[a]+=b;
C[a]++;
}
for(int i=1;i<=m;i++){
double oup=S[i];
oup/=C[i];
cout << fixed << setprecision(12) << oup << "\n";
}
return 0;
}
posted:
last update: