Last active
March 7, 2019 11:35
-
-
Save fpdjsns/dc60fba5843c2d305c9c2ff5e247bb73 to your computer and use it in GitHub Desktop.
[Round 1C 2017] Problem A. Ample Syrup : https://code.google.com/codejam/contest/3274486/dashboard#s=p0&a=0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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