Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. /**
  10. * Auto-generated code below aims at helping you parse
  11. * the standard input according to the problem statement.
  12. **/
  13.  
  14. bool sortOnX (vector<int> i,vector<int> j) { return (i.at(0)<j.at(0)); }
  15.  
  16.  
  17. int main()
  18. {
  19. int N;
  20. cin >> N; cin.ignore();
  21.  
  22. bool firstTime = true;
  23.  
  24. int startingX = 0;
  25. int furthestX = 0;
  26.  
  27. int averageY = 0;
  28. vector<int> Yvalues;
  29.  
  30. for (int i = 0; i < N; ++i) {
  31.  
  32. int X;
  33. int Y;
  34.  
  35. cin >> X >> Y; cin.ignore();
  36.  
  37. if(firstTime)
  38. {
  39. int startingX = X;
  40. int furthestX = X;
  41. firstTime = false;
  42. }
  43.  
  44. Yvalues.push_back(Y);
  45.  
  46. if(startingX > X){
  47. startingX = X;
  48. }
  49.  
  50. if(furthestX < X){
  51. furthestX = X;
  52. }
  53. }
  54.  
  55. sort(Yvalues.begin(),Yvalues.end());
  56.  
  57. averageY = Yvalues.at(Yvalues.size()/2.f);
  58.  
  59. long long CableLength = 0;
  60.  
  61.  
  62. for(int x = 0; x < Yvalues.size(); ++x){
  63. CableLength += abs(Yvalues.at(x)-averageY);
  64. }
  65.  
  66.  
  67. CableLength += abs(startingX-furthestX);
  68. if(Yvalues.size() == 1)
  69. cout << 0;
  70. else
  71. cout << CableLength << endl;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement