Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- int b[1005], v[1005];
- int main(){
- int n;cin>>n;
- for(int i=0;i<n-1;i++){
- cin>>b[i];
- }
- for(int i=1;i<=n;i++){
- v[0]=i;
- for(int j=0;j<n-1;j++){
- v[j+1]=b[j]-v[j];
- }
- //make sure distinct
- set<int> S;
- for(int j=0;j<n;j++){
- S.insert(v[j]);
- }
- bool bad=false;
- for(int j=1;j<=n;j++)if(!S.count(j)){
- bad=true;
- }
- if(bad)continue;
- for(int j=0;j<n;j++){
- if(j!=n-1)cout<<v[j]<<" ";
- else cout<<v[j];
- }
- cout<<endl;
- break;
- }
- }
- //observations, observations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement