Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define fst first
- #define snd second
- #define all(x) (x).begin(), (x).end()
- #define rall(x) (x).rbegin(), (x).rend()
- #define clr(a, v) memset( a , v , sizeof(a) )
- #define pb push_back
- #define mp make_pair
- #define sz size()
- #define FORN( i , s , n ) for( int i = (s) ; i < (n) ; i++ )
- #define FOR( i , n ) FORN( i , 0 , n )
- #define FORIT( i , x ) for( typeof x.begin() i = x.begin() ; i != x.end() ; i++ )
- #define trace(x) cout << #x << ": " << x << endl;
- #define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl;
- #define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
- #define read ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- using namespace std;
- typedef long long int64;
- typedef vector <int> vi;
- typedef pair <int,int> ii;
- typedef vector <string> vs;
- typedef vector <ii> vii;
- int W[105];
- int H[105];
- int L[105];
- double R[105];
- double maxR[25010];
- int main(){
- int T,N;
- double P;
- cin>>T;
- FORN(caso, 1, T+1){
- printf("Case #%d: ", caso);
- cin>>N>>P;
- double aux = 0;
- FOR(i,N) {
- cin>>W[i]>>H[i];
- L[i] = min(W[i], H[i]) * 2;
- R[i] = sqrt( W[i]*W[i] + H[i]*H[i] ) * 2.0;
- P -= 2.0*(W[i] + H[i]);
- aux += 2.0*(W[i] + H[i]);
- }
- FOR(i, 25005) maxR[i] = -1e18;
- maxR[0] = 0.0;
- FOR(i,N) FORN(j, L[i], 25005) {
- maxR[j] = max ( maxR[j], maxR[j - L[i]] + R[i] );
- }
- double ans = 0;
- FOR(i,min((int)P+1,25005)) ans = max ( ans, min( P, maxR[i] ) );
- printf("%.08f\n",ans+aux);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement