Advertisement
ec1117

Untitled

Feb 6th, 2022
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. int b[1005], v[1005];
  6.  
  7. int main(){
  8.     int n;cin>>n;
  9.     for(int i=0;i<n-1;i++){
  10.         cin>>b[i];
  11.     }
  12.     for(int i=1;i<=n;i++){
  13.         v[0]=i;
  14.         for(int j=0;j<n-1;j++){
  15.             v[j+1]=b[j]-v[j];
  16.         }
  17.  
  18.         //make sure distinct
  19.         set<int> S;
  20.         for(int j=0;j<n;j++){
  21.             S.insert(v[j]);
  22.         }
  23.         bool bad=false;
  24.         for(int j=1;j<=n;j++)if(!S.count(j)){
  25.             bad=true;
  26.         }
  27.         if(bad)continue;
  28.        
  29.         for(int j=0;j<n;j++){
  30.             if(j!=n-1)cout<<v[j]<<" ";
  31.             else cout<<v[j];
  32.         }
  33.         cout<<endl;
  34.         break;
  35.     }
  36. }
  37.  
  38. //observations, observations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement