Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ios::sync_with_stdio(false);
  9.     int T;
  10.     cin>>T;
  11.     while(T--)
  12.     {
  13.         int skin;
  14.         int money;
  15.         cin >> skin;
  16.         cin >> money;
  17.         //cout<<"skin :      "<<skin<<endl;
  18.         //cout<<"money:      "<<money<<endl;
  19.         int unhappy[30+5];
  20.         memset(unhappy,0,sizeof(unhappy));
  21.         int happyday=(money-45*skin)/14;
  22.         //cout<<"Happy day :      "<<happyday<<endl;
  23.         int unhappyValue=0;
  24.         if(happyday>=skin/2&&happyday<skin)
  25.         {
  26.             unhappyValue=skin-happyday;
  27.         }
  28.         else if(happyday>=skin)
  29.         {
  30.             unhappyValue=0;
  31.         }
  32.         else if(happyday==0)
  33.         {
  34.             for(int i=1;i<=skin;i++)
  35.             {
  36.                 unhappy[i]=i;
  37.             }
  38.             for(int i=1;i<=skin;i++)
  39.                 unhappyValue+=unhappy[i];
  40.         }
  41.         else
  42.         {
  43.             for(int i=1;i<=skin;i++)
  44.             {
  45.                 unhappy[i]=i;
  46.             }
  47.             unhappy[skin/2]=0;
  48.  
  49.             /*for(int i=0;i<=skin+1;i++)
  50.                cout<<unhappy[i]<<" ";
  51.             cout<<endl;*/
  52.             int m=happyday-1;
  53.             int start =0;
  54.                 for(int j=1;j<=skin+1;j++)
  55.                     {
  56.                         if(unhappy[j]==0)
  57.                         {
  58.                             unhappy[start+(j-start)/2]=0;
  59.                             m--;
  60.                             start=j;
  61.                             /*for(int i=0;i<=skin+1;i++)
  62.                                 cout<<unhappy[i]<<" ";
  63.                             cout<<endl;*/
  64.                         }
  65.                         if(m==0) break;
  66.                     }
  67.  
  68.             for(int i=skin;i>=1;i--)
  69.             {
  70.                 if(unhappy[i]==0)
  71.                 {
  72.                     int q=1;
  73.                     for(int m=i+1;unhappy[m]!=0;m++)
  74.                     {
  75.                         unhappy[m]=q;
  76.                         q++;
  77.                     }
  78.                 }
  79.             }
  80.             /*for(int i=0;i<=skin+1;i++)
  81.                cout<<unhappy[i]<<" ";
  82.             cout<<endl;*/
  83.             for(int i=1;i<=skin;i++)
  84.                 unhappyValue+=unhappy[i];
  85.         }
  86.         cout<<unhappyValue<<endl;
  87.         //cout<<T;
  88.     }
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement