Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Last active March 7, 2019 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpdjsns/dc60fba5843c2d305c9c2ff5e247bb73 to your computer and use it in GitHub Desktop.
Save fpdjsns/dc60fba5843c2d305c9c2ff5e247bb73 to your computer and use it in GitHub Desktop.
//
// Created by fpdjsns
// Copyright © 2019 fpdjsns. All rights reserved.
//
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
int main() {
int T;
cin >> T;
double PI = 3.1415926535897932;
for (int c = 1; c <= T; c++) {
int N, K;
cin >> N >> K;
vector<pair<int, int>> arr(N);//R, H
for (int i = 0; i < N; i++){
cin >> arr[i].first >> arr[i].second;
}
sort(arr.begin(), arr.end());
long long int answer = 0;
long long int R = 0;
long long int H = 0;
long long int sumH = 0;
priority_queue<long long int,vector<long long int>,greater<long long int>> q;
for (int i = 0; i < K; i++) {
R = arr[i].first;
H = 2*R*arr[i].second;
q.push(H);
sumH += H;
}
answer = R * R + sumH;
for (int biggest = K; biggest < N; biggest++) {
R = arr[biggest].first;
H = 2*R*arr[biggest].second;
sumH += H;
sumH -= q.top();
q.pop();
q.push(H);
answer = max(answer, R*R + sumH);
}
/* output */
printf("Case #%d: %7lf\n", c, answer * PI);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment