1491B - Minimal Cost - CodeForces Solution


brute force math *1200

Please click on ads to support us..

C++ Code:

/*

 JAI BHEEM            JABTAK TODEGA NAHI                        JAI BHARAT
                      TABTAK CHODEGA NAHI

*/
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ulli unsigned long long int
#define lld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define nl "\n"
#define fl(i,a) for(lli i=0;i<a;i++)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) x.begin(),x.end()
#define vlli vector<lli>
#define mlli map<lli,lli>
#define slli set<lli>
#define mslli multiset<lli>
lli ceil(lli a,lli b){
    if(a%b==0)
    return a/b;
    return (a/b+1);
}
bool cmp(lli x,lli y){
return x>y;}
  lli pow(lli a,lli b,lli m){
     if(a==0)
     return 0;
     if(b==0)
     return 1;
     lli k=pow(a,b/2,m);
     if(b%2==0){
         return (1LL*k*k)%m;
     }
     else{
         return (((1LL*k*k)%m)*a)%m;
     }
 }
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli t;
	t=1;
	cin>>t;
	for(int kk=1;kk<=t;kk++){
	   // cout<<"Case #"<<kk<<": ";
	lli n,a,b;
	cin>>n>>a>>b;
	vlli v(n);
	fl(i,n){
	    cin>>v[i];
	}
	    lli f=0;
	    lli tt=0;
	    fl(i,n-1)
	    {
	        if(abs(v[i+1]-v[i])>1)
	        f=1;
	        
	        if(abs(v[i+1]-v[i])==1)
	        tt=1;
	       // tt=min(tt,abs(v[i+1]-v[i]));
	    }
	    if(f)
	    cout<<0<<nl;
	    else{
	        if(tt==0)
	        cout<<min(a+b,2*b)<<nl;
	        else
	        cout<<min(a,b)<<nl;
	    }
	}
return 0;
}




Comments

Submit
0 Comments
More Questions

2144. Minimum Cost of Buying Candies With Discount
Non empty subsets
1630A - And Matching
1630B - Range and Partition
1630C - Paint the Middle
1630D - Flipping Range
1328A - Divisibility Problem
339A - Helpful Maths
4A - Watermelon
476A - Dreamoon and Stairs
1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves