645B - Mischievous Mess Makers - CodeForces Solution


greedy math *1200

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

#define fi first

#define se second

#define int long long

#define pb push_back

#define MOD 1000000007

int bigmod (int b, int p){

	if (p==0) return 1LL;

	if (p==1) return b%MOD;

	int cur=bigmod(b, p/2);

	cur=(cur*cur)%MOD;

	if (p%2==0) return cur;

	else return (b*cur)%MOD;

}

void solve(){

    int n, k;

    cin>>n>>k;

    n--;

    int cur=n;

    int ans=0;

    for (int i=1; i<=k; i++){

        if (cur<1) break;

        ans+=cur+cur-1;

        cur-=2;

    }

    cout<<ans<<endl;

}

signed main(){

    int t;

    t=1;

    while (t--) solve();

}


Comments

Submit
0 Comments
More Questions

363D - Renting Bikes
1198D - Rectangle Painting 1
1023B - Pair of Toys
1725A - Accumulation of Dominoes
1675E - Replace With the Previous Minimize
839A - Arya and Bran
16B - Burglar and Matches
1625B - Elementary Particles
1725G - Garage
1725B - Basketball Together
735A - Ostap and Grasshopper
1183B - Equalize Prices
1481A - Space Navigation
1437B - Reverse Binary Strings
1362B - Johnny and His Hobbies
1299A - Anu Has a Function
1111A - Superhero Transformation
954A - Diagonal Walking
39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction
1690E - Price Maximization
282B - Painting Eggs
440A - Forgotten Episode
233B - Non-square Equation
628B - New Skateboard
262B - Roma and Changing Signs
755C - PolandBall and Forest
456B - Fedya and Maths
376B - IOU