Advertisement
Guest User

Untitled

a guest
May 6th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <deque>
  6. #include <queue>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <cstdlib>
  19. #include <ctime>
  20. #include <cstring>
  21. #include <climits>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. using namespace std;
  25. #define REP(i,n) for(int i=0; i<n; i++)
  26. #define FOR(i,st,end) for(int i=st;i<end;i++)
  27. #define db(x) cout << (#x) << " = " << x << endl;
  28. #define mp make_pair
  29. #define pb push_back
  30. #define MAX 10000005
  31. typedef long long int ll;
  32. int main(){
  33. int n;
  34. int arr[100005];
  35. vector<int> ans;
  36. scanf("%d",&n);
  37. REP(i,n){
  38. scanf("%d",&arr[i]);
  39.  
  40. }
  41. sort(arr,arr+n);
  42. if(n==1){
  43. cout<<"-1";
  44. return 0;
  45. }
  46. if(n==2){
  47. int diff=arr[1]-arr[0];
  48. if(diff==0){
  49. cout<<"1"<<endl<<arr[0];
  50. return 0;
  51. }
  52. if(diff!=0&&diff%2==0){
  53. ans.pb(arr[0]+diff/2);
  54. }
  55. ans.pb(arr[0]-diff);
  56. ans.pb(arr[1]+diff);
  57. }
  58. else{
  59. map<int,int> m;
  60. FOR(i,1,n){
  61. m[arr[i]-arr[i-1]]++;
  62. }
  63. int ms=m.size();
  64. map<int,int>::iterator it;
  65. if(ms==1){
  66. it=m.begin();
  67. if(it->first==0){
  68. cout<<"1"<<endl<<arr[0];
  69. return 0;
  70. }
  71. ans.pb(arr[0]-it->first);
  72. ans.pb(arr[n-1]+it->first);
  73.  
  74. }
  75. else if(ms==2){
  76. vector<pair<int,int> >p;
  77. int minCountValue,maxCountValue;
  78. for(it=m.begin();it!=m.end();it++){
  79. p.pb(mp(it->first,it->second));
  80. }
  81. if(p[0].second==1||p[1].second==1){
  82. if(p[0].second==p[1].second){
  83. if(p[0].first<p[1].first){
  84. minCountValue=p[1].first;
  85. maxCountValue=p[0].first;
  86. }
  87. }
  88. else if(p[0].second<p[1].second){
  89. minCountValue=p[0].first;
  90. maxCountValue=p[1].first;
  91. }
  92. else{
  93. minCountValue=p[1].first;
  94. maxCountValue=p[0].first;
  95. }
  96. if(maxCountValue*2==minCountValue){
  97. FOR(i,1,n){
  98. if(arr[i]-arr[i-1]==minCountValue){
  99. ans.pb(arr[i-1]+maxCountValue);
  100. }
  101. }
  102.  
  103. }
  104. else{
  105. cout<<"0";
  106. return 0;
  107. }
  108. }
  109. else{
  110. cout<<"0";
  111. return 0;
  112. }
  113.  
  114. }
  115. }
  116. int ansSize=ans.size();
  117. cout<<ansSize<<endl;
  118. sort(ans.begin(),ans.end());
  119. REP(i,ansSize){
  120. cout<<ans[i]<<" ";
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement