Skip to content

Instantly share code, notes, and snippets.

@esbanarango
Created May 2, 2012 22:32
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 esbanarango/2581047 to your computer and use it in GitHub Desktop.
Save esbanarango/2581047 to your computer and use it in GitHub Desktop.
Tuenti, Challenge 4: 20 fast 20 furious
/*
Esteban Arango Medina
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,long> il;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <il> vil;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;
typedef map <int,vil> mivil;
#define INF 1000000000
int read_int () {
int ret = 0;
char c;
while((c = getchar_unlocked()) && c < '0' && c > '9'){
}
do {
ret *= 10;
ret += c-'0';
}while((c = getchar_unlocked()) && '0' <= c and c <= '9');
return ret;
}
int main(){
int t; scanf("%d",&t);
int r,k,g;
while(t--){
scanf("%d %d %d",&r,&k,&g);
vi groups(g);
char c =getchar_unlocked();
for (int i = 0; i < g; ++i){groups[i] = read_int();}
int resp =0;
int iter =0;
for (int i = 0, j=1; i < r; ++i,j=1)
{
int lleno =groups[iter%g];
while(lleno<k && groups[(iter+1)%g]+lleno<=k && j < g){
iter++;
lleno+=groups[iter%g];
j++;
}
iter++;
resp+=lleno;
}
cout<<resp<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment