Thursday, 3 October 2013

Candies Solution Hackerrank

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    
  int N;
  cin>>N;
  int *ar =  new int[N];
  int *ar1 = new int[N];
  for (int i=0; i<N; i++)
        cin>>ar[i];
  for (int i=0;i<N;i++)
  {
      ar1[i]=1;      
      if(i-1>=0)
      {
          if(ar[i-1]<ar[i])
            ar1[i] = ar1[i-1]+1;
          else 
          {
               int j = i;
               while(j>0 && ar[j-1] > ar[j])
               {
                ar1[j-1] = max(ar1[j-1],ar1[j] + 1);
                j= j-1;
               }          
          }
      }
  }
    int total = 0;
    for ( int i = 0; i<N ; i++){
        total += ar1[i];
    }
   cout<<total;
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    return 0;
}

2 comments:

  1. Graton Casino Hotel, Phoenix - Mapyro
    Graton Casino Hotel, Phoenix is a Phoenix-area casino with a 영주 출장샵 location in 제주도 출장안마 the suburb of 서귀포 출장안마 Phoenix, 안성 출장마사지 Arizona. It is owned and operated by 나주 출장샵 the Eastern Band of

    ReplyDelete

Chocolate Feast Solution Hackerrank

#include<iostream> using namespace std; int main() {     int t;     cin>>t;     while(t--)     {         int n,c,m,w,tot...