Forum Index



Reply to topic
Efort
Radbug
SUPREME DRINKER
SUPREME DRINKER
Radbug
Joined: 16 Oct 2009
Posts: 17
Reply with quote
Code:
#include <iostream.h>

unsigned long n,k,d,a,b,c,s1,dx,st;
int main()
{
   cin>>n;
   cin>>k;
   d=0;
   while(n>0)
   {
      while((d<k)&&(n>0))
      {
         cin>>dx;
         d=d+dx;
         n=n-1;
      }
      if(d>=k)
      {
         s1=k;
         d=d-k;
         a=1;
         b=1;
         while(d>0)
         {
            c=a+b;
            s1=s1+c;
            d=d-1;
            a=b;
            b=c;
         }
         st=st+s1;
      }
      else
         st=st+d;
      d=0;
      s1=0;
   }
   cout<<st<<'\n';
}
View user's profileSend private message
Efort
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT + 2 Hours  
Page 1 of 1  

  
  
 Reply to topic