Skip to main content

AtCoder Beginner Contest 247(E - Max Min)



 We think about this case:
input:10 8 1
      2 1 8 3 1 8 9 1 8 2
Output:14 

Explanation:-
2(11(28(33(41(58(69(71(88(96(10)
When we work on 2 then no pair added
When we work on 1 then no pair added
When we work on 8 then 2 pair added
     1 to 3
     2 to 3
When we work on 3 then 2 pair added
     1 to 4
     2 to 4
When we work on 1 then 3 pair added
     1 to 5
     2 to 5
     3 to 5
When we work on 8 then 2 pair added
     1 to 6
     2 to 6
     3 to 6
     4 to 6
     5 to 6
When we work on 9(Special case)
    Because any pair with this value will be incorrect because it is greater than X
    It can also be if there are any value less than Y
When we work on 1 then no pair added
When we work on 8 then 1 pair added
     8 to 9
When we work on 8 then 1 pair added
     8 to 10
So all eligible pairs
Pair no 1(1 to 3)
Pair no 2(2 to 3)
Pair no 3(1 to 4)
Pair no 4(2 to 4)
Pair no 5(1 to 5)
Pair no 6(2 to 5)
Pair no 7(1 to 5)
Pair no 8(1 to 6)
Pair no 9(2 to 6)
Pair no 10(3 to 6)
Pair no 11(4 to 6)
Pair no 12(5 to 6)
Pair no 13(8 to 9)
Pair no 14(8 to 10)


///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
  angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;

int main()
{
    ll n,x,y,pre=0,pre_x=-1,pre_y=-1,num,ans=0;
    cin>>n>>x>>y;
    for(ll i=1;i<=n;i++)
    {
        cin>>num;
        if(y<=num && num<=x)
        {
            if(num==x) pre_x=i;
            if(num==y) pre_y=i;
            if(min(pre_x,pre_y)>pre && pre_x!=(-1) && pre_y!=(-1)) ans+=(min(pre_x,pre_y)-pre);
        }
        else pre=i;
    }
    cout<<ans<<endl;
    return 0;
}
///Alhamdulillah

Problem link:https://atcoder.jp/contests/abc247/tasks/abc247_e

Comments

Popular posts from this blog

Codeforces round 1676(A. Lucky?)

Just count the  first three  &  last three  number ///Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is repres...

Maximum Number of Coins You Can Get (LeetCode)

Problem Name: 1561.  Maximum Number of Coins You Can Get Problem Link: https://leetcode.com/problems/maximum-number-of-coins-you-can-get/description/ Difficulty: Medium Tag: Sorting | Array | Math | Greedy | Sorting | Game theory Language: C# | C++ OJ: LeetCode Algorithm: Sort the Piles: Sort the array of piles in descending order, so that the piles with the maximum number of coins are at the beginning. Calculate the Total Number of Piles to Collect From: Determine the total number of piles you can collect coins from based on the rule that for every three consecutive piles, you can only pick coins from two of them. Set this value to 2/3 of the total number of piles. Iterate Through Piles and Collect Coins: Start iterating through the sorted piles from the second pile (index 1) and continue up to the calculated total number of piles to collect from. In each iteration, collect the coins from the current pile. Since you can only collect coins from every second pile, use a step of ...

Codeforces round 1661(B. Getting Zero)

using   second operation  the answer is maximum is  15  because  2 15 =32768 so we need to  pre-calculate all the illegible input 0 to 32768   using  second operation Then  just increment 1(using first operation)  from input check is it  minimum is not ! ///Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int...