fork download
  1. #include<bits/stdc++.h>
  2. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define Toggle(n,i) (n^((ll)1<<i))
  6. #define Check(n,i) (n&((ll)1<<i))
  7. #define Set(n,i) (n|((ll)1<<i))
  8. #define Reset(n,i) (n&(~((ll)1<<i)))
  9. #define fo(a,x,y) for(int i=(x);i<=(y);++i){cout<<a[i]<<" ";}cout<<endl;
  10. #define me(arr,val) memset(arr,val,sizeof arr)
  11. #define inf INT_MAX
  12. #define infd DBL_MAX
  13. #define infl LLONG_MAX
  14. #define mod 1000000007ll
  15. #define f first
  16. #define s second
  17. #define pra(a) for(auto i:a){cout<<i<<endl;}
  18. #define all2(a,start,n) a.begin()+start,a.begin()+start+n
  19. #define all(a) a.begin(),a.end()
  20. #include<ext/pb_ds/assoc_container.hpp>
  21. #include<ext/pb_ds/tree_policy.hpp>
  22. //int dx[]={+1,-1,0,0};//vertical horizontal
  23. //int dy[]={0,0,+1,-1};//vertical horizontal
  24. //int dx[]={+1,+1,-1,-1,+2,-2,+2,-2};//knights move
  25. //int dy[]={+2,-2,+2,-2,+1,+1,-1,-1};//knights move
  26. //int dx[]={+1,-1,0,0,+1,+1,-1,-1};//vertical horizontal diagonal
  27. //int dy[]={0,0,+1,-1,-1,+1,+1,-1};//vertical horizontal diagonal
  28. using namespace std;
  29. using namespace __gnu_pbds;
  30. /*typedef tree<int, null_type,less<int>, rb_tree_tag,
  31.   tree_order_statistics_node_update>indexed_set;
  32. for set use above*/
  33. typedef tree<pair<int,int>, null_type,less<pair<int, int>>, rb_tree_tag,
  34. tree_order_statistics_node_update> indexed_multiset;
  35. template < typename F, typename S >
  36. ostream& operator << ( ostream& os, const pair< F, S > & p ) {
  37. return os << "(" << p.first << ", " << p.second << ")";
  38. }
  39. template < typename T >
  40. ostream &operator << ( ostream & os, const vector< T > &v ) {
  41. os << "{";
  42. typename vector< T > :: const_iterator it;
  43. for( it = v.begin(); it != v.end(); it++ ) {
  44. if( it != v.begin() ) os << ", ";
  45. os << *it;
  46. }
  47. return os << "}";
  48. }
  49. template < typename T >
  50. ostream &operator << ( ostream & os, const set< T > &v ) {
  51. os << "[";
  52. typename set< T > :: const_iterator it;
  53. for ( it = v.begin(); it != v.end(); it++ ) {
  54. if( it != v.begin() ) os << ", ";
  55. os << *it;
  56. }
  57. return os << "]";
  58. }
  59. template < typename T >
  60. ostream &operator << ( ostream & os, const multiset< T > &v ) {
  61. os << "[";
  62. typename multiset< T > :: const_iterator it;
  63. for ( it = v.begin(); it != v.end(); it++ ) {
  64. if( it != v.begin() ) os << ", ";
  65. os << *it;
  66. }
  67. return os << "]";
  68. }
  69. template < typename F, typename S >
  70. ostream &operator << ( ostream & os, const map< F, S > &v ) {
  71. os << "[";
  72. typename map< F , S >::const_iterator it;
  73. for( it = v.begin(); it != v.end(); it++ ) {
  74. if( it != v.begin() ) os << ", ";
  75. os << it -> first << " = " << it -> second ;
  76. }
  77. return os << "]";
  78. }
  79. #define pr(x) cerr << #x << " = " << x << endl;
  80.  
  81. int main()
  82. {
  83. ios_base::sync_with_stdio(false);
  84. cin.tie(NULL);
  85. double n,m;
  86. double sum=0;
  87. cin>>n>>m;
  88. while(m--)
  89. {
  90. double x,d;
  91. cin>>x>>d;
  92. if(d>=0.0)
  93. {
  94. sum+=d*((n*(n-1))/2.0)+x*n;
  95. //pr(sum);
  96. }
  97. else
  98. {
  99. ll n2=((ll)n-1)/2;
  100. //pr(n2);
  101. sum+=(d*((n2*(n2+1))/2.0))*2.0+x*n;
  102. if((ll)n%2==0)
  103. sum+=(n/2)*d;
  104. //pr(sum);
  105. }
  106. }
  107. cout<<fixed<<setprecision(9)<<sum/n;
  108. return 0;
  109. }
  110.  
  111.  
Time limit exceeded #stdin #stdout 5s 4812KB
stdin
Standard input is empty
stdout
Standard output is empty