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

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

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;
}

📦 Looking for Codeforces Round 387 Div Problem Servers? Check the best deals on Amazon.

🛒 Shop Codeforces Round 387 Div Problem Servers on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

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;
}

📦 Looking for Codeforces Round 387 Div Problem Servers? Check the best deals on Amazon.

🛒 Shop Codeforces Round 387 Div Problem Servers on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Is Viral Kitchen Gadgets Worth Your Money Here Is Our Full Review

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

Yongxing YogasuitFactory Seamless Thermal Underwear For Winter

When winter arrives, dressing for the freezing weather often feels like an uncomfortable compromise between staying warm and retaining natural freedom of movement. Bulky...

How Viral Kitchen Gadgets Is Quietly Changing the Game

📢 As an Amazon Associate, I earn from qualifying purchases.I stumbled across this while desperately trying to fix a recurring problem in my routine....

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!