Codeforces Round #387 (Div. 2), problem: (C) Servers Solution in C/C++

#include<stdio.h> int main(){ int n,q,a[100]={0},t,k,d,i,j,s,f; scanf("%d%d",&n,&q); while(q>0) { scanf("%d%d%d",&t,&k,&d); s=0; for(i=0;i<n;i++) { if(a[i]<t) a[i]=0; } j=0; for(i=0;i<n;i++) { if(a[i]==0) j++; } if(j<k) printf("-1\n"); else {for(i=0,j=0;i<n&&j<k;i++) { if(a[i]==0) { s+=i+1; a[i]=t+d-1;j++;} } printf("%d\n",s);} q--; } return 0; }