Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,a,b,i,x,y,mn=INT_MAX,cost,t,j,p,q;
- cin>>t;
- for(j=0; j<t; j++)
- {
- cin>>n;
- cin>>a;
- cin>>b;
- if(a<b)
- {
- p=a;
- q=b;
- }
- else
- {
- q=a;
- p=b;
- }
- mn=INT_MAX,x=1,cost=0;
- for(i=1; i<=n; i++)
- {
- cost=(p*i*i)+(q*(n-i)*(n-i));
- if(cost<mn)
- {
- mn=cost;
- if(i==n)
- {
- x=i;
- break;
- }
- }
- else if(cost>mn)
- {
- x=i;
- break;
- }
- }
- if(a<b)
- {
- if(n>1&&i!=n)
- cout<<mn<<" "<<x-1<<" "<<n-x+1<<endl;
- else
- cout<<mn<<" "<<x<<" "<<n-x<<endl;
- }
- else
- {
- if(n>1&&i!=n)
- cout<<mn<<" "<<n-x+1<<" "<<x-1<<endl;
- else
- cout<<mn<<" "<<n-x<<" "<<x<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement