// Task: b.cc // Created at Wed, Nov 22, 2017 00:46:23 AM #include <bits/stdc++.h> using namespace std; namespace { struct point_t; using i64 = int64_t; using u64 = uint64_t; #define all(x) begin(x),end(x) template<typename T = int> T read(); template<typename T = int> vector<T> read_vec(size_t const n); template<typename T>ostream& operator<<(ostream& os, vector<T> const vec); template<typename T> T gcd(T const a, T const b); } int main(int, char**) { cin.tie(nullptr); ios_base::sync_with_stdio(false); auto n = read<i64>(); auto m = read<i64>(); map<i64, i64> freq; vector<i64> t(n+1, 0); for(int i=1; i<=n; ++i) { cin >> t[i]; ++freq[t[i] - t[i-1]]; } while(m--) { auto dur = read<i64>(); i64 ans = 0LL; for(const auto x : freq) { if(x.first > dur) break; ans += (dur - x.first) * x.second; } cout << ans << '\n'; } } /************************************************************************************************** ********************************* DEFINITIONS OF HELPER FUNCTIONS ******************************** **************************************************************************************************/ namespace { template<typename T = int> T read() { T x; cin >> x; return x; } template<typename T = int> vector<T> read_vec(size_t const n) { vector<T> vec(n); copy_n(istream_iterator<T>(cin), n, begin(vec)); return vec; } template<typename T> ostream& operator<<(ostream& os, vector<T> const vec) { copy(begin(vec), end(vec), ostream_iterator<T>(os, " ")); return os; } template<typename T> T gcd(T const a, T const b) { return a==0 ? b : gcd(b%a, a); } struct point_t { int x, y; point_t(int _x, int _y) : x{_x}, y{_y} {} friend istream& operator>>(istream& is, point_t& p) { is>>p.x>>p.y; return is; } }; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | // Task: b.cc // Created at Wed, Nov 22, 2017 00:46:23 AM #include <bits/stdc++.h> using namespace std; namespace { struct point_t; using i64 = int64_t; using u64 = uint64_t; #define all(x) begin(x),end(x) template<typename T = int> T read(); template<typename T = int> vector<T> read_vec(size_t const n); template<typename T>ostream& operator<<(ostream& os, vector<T> const vec); template<typename T> T gcd(T const a, T const b); } int main(int, char**) { cin.tie(nullptr); ios_base::sync_with_stdio(false); auto n = read<i64>(); auto m = read<i64>(); map<i64, i64> freq; vector<i64> t(n+1, 0); for(int i=1; i<=n; ++i) { cin >> t[i]; ++freq[t[i] - t[i-1]]; } while(m--) { auto dur = read<i64>(); i64 ans = 0LL; for(const auto x : freq) { if(x.first > dur) break; ans += (dur - x.first) * x.second; } cout << ans << '\n'; } } /************************************************************************************************** ********************************* DEFINITIONS OF HELPER FUNCTIONS ******************************** **************************************************************************************************/ namespace { template<typename T = int> T read() { T x; cin >> x; return x; } template<typename T = int> vector<T> read_vec(size_t const n) { vector<T> vec(n); copy_n(istream_iterator<T>(cin), n, begin(vec)); return vec; } template<typename T> ostream& operator<<(ostream& os, vector<T> const vec) { copy(begin(vec), end(vec), ostream_iterator<T>(os, " ")); return os; } template<typename T> T gcd(T const a, T const b) { return a==0 ? b : gcd(b%a, a); } struct point_t { int x, y; point_t(int _x, int _y) : x{_x}, y{_y} {} friend istream& operator>>(istream& is, point_t& p) { is>>p.x>>p.y; return is; } }; } |