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. ll n,m,sum=0;
86. cin>>n>>m;
87. while(m--)
88. {
89. ll x,d;
90. cin>>x>>d;
91. if(d>=0)
92. {
93. sum+=d*((n*(n-1))/2)+x*n;
94. //pr(sum);
95. }
96. else
97. {
98. ll n2=(n-1)/2;
99. //pr(n2);
100. sum+=(d*((n2*(n2+1))/2))*2+x*n;
101. if(n%2==0)
102. sum+=(n/2)*d;
103. //pr(sum);
104. }
105. }
106. cout<<fixed<<setprecision(15)<<(double)sum/n;
107. return 0;
108. }
109.
110.
Time limit exceeded #stdin #stdout 5s 4908KB
stdin
Standard input is empty
stdout
Standard output is empty