Sunday, 3 September 2017

CodeForce Problem 588A - Duff and Meat Solution (C++)


Problem:

Please find the problem here
.

Solution:

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

Code:




The code is explained below using Comments(//)

//http://codeforces.com/problemset/problem/588/A

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=b;i++)            // Loop starts from a and ends at b
main(){
int n,a,p;
cin>>n;                                                               //Input taken
int mi =200;
int cost=0;
REP(i,0,n-1){
cin>>a;
cin>>p;
mi=min(mi,p);                                                     //Finding the minimum and replacing the minimum.
cost =cost+(a*mi);                                              // Multiplying minimum with required amount .
}                                                                          // Add to Cost
cout<<cost<<endl;    
}









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...