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 Beta Round #53 (A. Square Earth?)

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

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

AtCoder Beginner Contest 237(D - LR insertion)

Problem solving criteria:stack (https://www.cplusplus.com/reference/stack/stack/) Think about the first input: LRRLR That means  0 ->(L)-> 1 ->(R)-> 2 ->(R)-> 3 ->(L)-> 4 ->(R)-> 5 so we just need to save first R right number  in  an  array (vector) & other number saves  in  a stack. 0 ->(L)-> 1   general  array (vector)       stack( 0 )   top of stack= 0 1 ->(R)-> 2   general  array (vector)= 1      stack( 0 )   top of stack= 0 2 ->(R)-> 3   general  array (vector)= 1 , 2    stack( 0 )   top of stack= 0 3 ->(L)-> 4   general  array (vector)= 1 , 2    stack( 0 , 4 )...