Educational Codeforces Round 77 (Rated for Div. 2)
A. Heating
Several days ago you bought a new house and now you are planning to start a renovation. Since winters in your region can be very cold you need to decide how to heat rooms in your house.
Your house has nn rooms. In the ii-th room you can install at most cici heating radiators. Each radiator can have several sections, but the cost of the radiator with kk sections is equal to k2k2 burles.
Since rooms can have different sizes, you calculated that you need at least sumisumi sections in total in the ii-th room.
For each room calculate the minimum cost to install at most cici radiators with total number of sections not less than sumisumi.
The first line contains single integer nn (1≤n≤10001≤n≤1000) — the number of rooms.
Each of the next nn lines contains the description of some room. The ii-th line contains two integers cici and sumisumi (1≤ci,sumi≤1041≤ci,sumi≤104) — the maximum number of radiators and the minimum total number of sections in the ii-th room, respectively.
For each room print one integer — the minimum possible cost to install at most cici radiators with total number of sections not less than sumisumi.
4 1 10000 10000 1 2 6 4 6
100000000 1 18 10
In the first room, you can install only one radiator, so it's optimal to use the radiator with sum1sum1 sections. The cost of the radiator is equal to (104)2=108(104)2=108.
In the second room, you can install up to 104104 radiators, but since you need only one section in total, it's optimal to buy one radiator with one section.
In the third room, there 77 variants to install radiators: [6,0][6,0], [5,1][5,1], [4,2][4,2], [3,3][3,3], [2,4][2,4], [1,5][1,5], [0,6][0,6]. The optimal variant is [3,3][3,3] and it costs 32+32=1832+32=18.
#include <iostream> #include <algorithm> #include <cstdio> #include <string> #include <cstring> #include <cstdlib> #include <map> #include <vector> #include <set> #include <queue> #include <stack> #include <cmath> using namespace std; #define mem(s,t) memset(s,t,sizeof(s)) #define pq priority_queue #define pb push_back #define fi first #define se second #define ac return 0; #define ll long long #define cin2(a,n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j]; #define rep_(n,m) for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) #define rep(n) for(int i=1;i<=n;i++) #define test(xxx) cout<<" Test " <<" "<<xxx<<endl; #define TLE std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); #define lc now<<1 #define rc now<<1|1 #define ls now<<1,l,mid #define rs now<<1|1,mid+1,r #define half no[now].l+((no[now].r-no[now].l)>>1) #define ll long long #define mod 1000000007 const int mxn = 1e6+10; ll n,m,k,ans,col,t,flag,x,y,pim[mxn]; ll a[mxn],sum[mxn],cnt,vis[mxn]; vector<int>G[mxn],v; string str, ch,s1,s2; //pair <int,int> pa[mxn]; const int maxn = 1000+8; const int inf = 0x3f3f3f; int p, r, sign[maxn]; int main() { cin>>t; while(t--) { cin>>n>>m; if(m==1) cout<<1<<endl; else if(m<n) cout<<m<<endl; else if(m%n==0) cout<<(ll)n*(m/n)*(m/n)<<endl; else { ll ans = m/n; cout<<(m%n)*(ans+1)*(ans+1)+(n-m%n)*ans*ans<<endl; } } return 0; }
B. Obtain Two Zeroes