Thursday, 21 September 2017

CodeForces Problem 863B - Kayaking Solution (C++)

Problem:

Please find the problem 
here.

Solution:

This is the easiest problem I ever had, just implement the given formulas! However, it does take me some time to write.



Code:
#include<bits/stdc++.h>
using namespace std;
int a[100],b[100];
main(){
    int n;
    cin>>n;
    for(int i=0;i<2*n;i++){
        cin>>a[i];
    }
    int maximum = 1000000;
    for(int i=0;i<2*n;i++){
        for(int j=i+1;j<2*n;j++){
            for(int k=0;k<2*n;k++){
             b[k]=a[k];
            }

        b[i]=b[j]= -1;
        sort(b,b+2*n);
             int ans=0;

        for(int k=2;k<2*n-1;k+=2){
           ans+= b[k+1]- b[k];
        }

        maximum=min(maximum,ans);
        }

    }

    cout<<maximum;




}

No comments:

Post a Comment

Spoj Problem ACMCEG2C - Pick the candies (C++)

  The problem link may be found here.       Explanation: Use Deque to keep track of elements of the variety of candies. If i is gre...