https://codeforces.com/contest/1305/problem/E
题意:要求构造n个数满足m个平衡,平衡规则:(i , j , k)1 <= i < j < k <= n && ai + aj = ak .
解法:构造1 ,2 , 3 ..... n 可知该序列有最大得平衡数,可知每一个数可贡献 (i - 1) / 2 个平衡,所以可算得最大平衡数。
大于最大平衡数则不能构造出该序列。
遍历:如果当前所需平衡数m >= (i-1) / 2 , 则ai = i .
否则 该数为 (i-1)*2+1 - 2*(m) ,此时满足了平衡数已经达到要求,无需再贡献平衡数。
如果后面还有数则为1000000000-(n-i)* 10000,可以避免贡献平衡数。
//#include<bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <string> #include <stdio.h> #include <queue> #include <stack> #include <map> #include <set> #include <string.h> #include <vector> typedef long long ll ; #define int ll #define mod 1000000007 #define gcd __gcd #define rep(i , j , n) for(int i = j ; i <= n ; i++) #define red(i , n , j) for(int i = n ; i >= j ; i--) #define ME(x , y) memset(x , y , sizeof(x)) //ll lcm(ll a , ll b){return a*b/gcd(a,b);} //ll quickpow(ll a , ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;b>>=1,a=a*a%mod;}return ans;} //int euler1(int x){int ans=x;for(int i=2;i*i<=x;i++)if(x%i==0){ans-=ans/i;while(x%i==0)x/=i;}if(x>1)ans-=ans/x;return ans;} //const int N = 1e7+9; int vis[n],prime[n],phi[N];int euler2(int n){ME(vis,true);int len=1;rep(i,2,n){if(vis[i]){prime[len++]=i,phi[i]=i-1;}for(int j=1;j<len&&prime[j]*i<=n;j++){vis[i*prime[j]]=0;if(i%prime[j]==0){phi[i*prime[j]]=phi[i]*prime[j];break;}else{phi[i*prime[j]]=phi[i]*phi[prime[j]];}}}return len} #define INF 0x3f3f3f3f #define PI acos(-1) #define pii pair<int,int> #define fi first #define se second #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define cin() scanf("%lld" , &x); using namespace std; const int esp = 1e-6; const int maxn = 5e5+5; void solve(){ int n , m ; cin >> n >> m ; int ma = ((1 + (n-1)/2)*((n-1)/2))/2; if(n % 2 == 1){ ma *= 2 ; ma -= (n-1)/2; }else ma *= 2 ; if(m > ma){ cout << -1 << endl; return ; }else{ rep(i , 1 , n){ if(m == 0){ cout << 100000000 - (n-i)*10000 << " " ; }else if(m >= (i-1)/2){ cout << i << " " ; m -= (i-1)/2 ; }else{ cout << 2*(i-1)+1 - 2*(m) << " " ; m = 0 ; } } } } signed main() { //ios::sync_with_stdio(false); //cin.tie(0); cout.tie(0); //int t ; //cin >> t ; //while(t--){ solve(); //} }