Cost Of Balloons
C Solution:
- #include<stdio.h>
- int main( ){
- long int tc,g,p,sum,n,t1,t2;
- scanf("%ld",&tc);
- for(int i=1;i<=tc;i++){
- scanf("%ld %ld",&g,&p);
- scanf("%ld",&n);
- for(int j=1;j<=n;j++){
- if(i%2==1){
- scanf("%ld %ld",&t1,&t2);
- sum=sum+(t1*g)+(t2*p);
- }
- else{
- scanf("%ld %ld",&t1,&t2);
- sum=sum+(t1*p)+(t2*g);
- }
- }
- printf("%d\n",sum);
- sum=0;
- }
- return 0;
- }
C++ Solution:
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int T;
- cin>>T;
- while(T--)
- {
- int C1, C2;
- cin>>C1>>C2;
- int n;
- cin>>n;
- int cost = 0;
- int a[n][2];
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<2; j++)
- {
- cin>>a[i][j];
- }
- }
- for(int i=0; i<n; i++)
- {
- if(a[i][0]==1)
- {
- cost = cost + 1*C1;
- }
- if(a[i][1]==1)
- {
- cost = cost + 1*C2;
- }
- }
- int cost2=0;
- for(int i=0; i<n; i++)
- {
- if(a[i][0]==1)
- {
- cost2 = cost2 + 1*C2;
- }
- if(a[i][1]==1)
- {
- cost2 = cost2 + 1*C1;
- }
- }
- cout<<min(cost, cost2)<<endl;
- }
- return 0;
- }
Note:
We
Are Providing Every Content in this Blog Inspired From Many People and
Provide it Open To All People Who Are Willing Gain Some Stuff in
Computer Science.
Post a Comment
Post a Comment
Learn, Share and Enjoy