1.CodeForces 112C

找一种可能满足其所给条件,为了让平方和尽可能大,那么我们总和总是取最大为y,分这个y时,尽可能少分这样得到的平方和才最大,所以其他元素都只分到1,留下一个最大元素,这里注意如果每个都分1不够分,直接表示无答案

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define ll long long
const int N = 100005;
int a[N];
int main()
{
   // freopen("a.in" , "r" , stdin);
    int n , y;
    ll x ;
    while(scanf("%d%I64d%d" , &n , &x , &y) == 3)
    {
        if(y < n){
            puts("-1");
            continue;
        }
        ll ans = 0;
        for(int i=1 ; i<=n ; i++) a[i]=1;
        a[1] = y-n+1;
        ans = (ll)a[1]*a[1] + (ll)(n-1);
        if(ans >= x){
            for(int i=1 ; i<=n ; i++)
                printf("%d\n" , a[i]);
        }
        else  puts("-1");
    }
    return 0;
}
View Code

相关文章:

  • 2022-12-23
  • 2021-10-04
  • 2022-01-15
  • 2021-12-01
  • 2021-05-01
  • 2021-05-29
  • 2022-03-08
  • 2022-01-04
猜你喜欢
  • 2021-11-06
  • 2021-11-09
  • 2021-10-11
  • 2022-03-07
  • 2021-12-21
  • 2022-01-18
  • 2022-12-23
相关资源
相似解决方案