Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 3, 2016 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/599248d93d71a0155a0b to your computer and use it in GitHub Desktop.
Save jianminchen/599248d93d71a0155a0b to your computer and use it in GitHub Desktop.
HackerRank algorithm
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#include <iomanip>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll big = 1000000007ll;
ll n,m,k,q,d;
ll T;
std::vector<ll> A;
int main()
{
ll c1,c2,c3,c4,c5,c6;
ll x,y,z;
ll a,b,c,e;
ll s;
//freopen("test_input.txt","r",stdin);
//freopen("output.txt","w",stdout);
std::cin >> n >> k;
ll pn = 1;
ll ans = 0;
for(c1=0;c1<n;c1++){
std::cin >> a;
A.push_back(a);
ll t = 0;
while(t < a){
if(pn > t && pn <= min(t+k,a)){ans++;}
pn++;
t += k;
}
}
std::cout << ans << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment