Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cmath>
- using namespace std;
- int main()
- {
- ios::sync_with_stdio(false);
- int T;
- cin>>T;
- while(T--)
- {
- int skin;
- int money;
- cin >> skin;
- cin >> money;
- //cout<<"skin : "<<skin<<endl;
- //cout<<"money: "<<money<<endl;
- int unhappy[30+5];
- memset(unhappy,0,sizeof(unhappy));
- int happyday=(money-45*skin)/14;
- //cout<<"Happy day : "<<happyday<<endl;
- int unhappyValue=0;
- if(happyday>=skin/2&&happyday<skin)
- {
- unhappyValue=skin-happyday;
- }
- else if(happyday>=skin)
- {
- unhappyValue=0;
- }
- else if(happyday==0)
- {
- for(int i=1;i<=skin;i++)
- {
- unhappy[i]=i;
- }
- for(int i=1;i<=skin;i++)
- unhappyValue+=unhappy[i];
- }
- else
- {
- for(int i=1;i<=skin;i++)
- {
- unhappy[i]=i;
- }
- unhappy[skin/2]=0;
- /*for(int i=0;i<=skin+1;i++)
- cout<<unhappy[i]<<" ";
- cout<<endl;*/
- int m=happyday-1;
- int start =0;
- for(int j=1;j<=skin+1;j++)
- {
- if(unhappy[j]==0)
- {
- unhappy[start+(j-start)/2]=0;
- m--;
- start=j;
- /*for(int i=0;i<=skin+1;i++)
- cout<<unhappy[i]<<" ";
- cout<<endl;*/
- }
- if(m==0) break;
- }
- for(int i=skin;i>=1;i--)
- {
- if(unhappy[i]==0)
- {
- int q=1;
- for(int m=i+1;unhappy[m]!=0;m++)
- {
- unhappy[m]=q;
- q++;
- }
- }
- }
- /*for(int i=0;i<=skin+1;i++)
- cout<<unhappy[i]<<" ";
- cout<<endl;*/
- for(int i=1;i<=skin;i++)
- unhappyValue+=unhappy[i];
- }
- cout<<unhappyValue<<endl;
- //cout<<T;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement