Editorial for Bedao Grand Contest 10 - EVENT
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Ta sắp xếp các bài tập theo số điểm giảm dần. Gọi ~pre[i]~ là tổng số điểm ~i~ bài tập đầu tiên sau khi sắp xếp. Dễ dàng nhận thấy kết quả cho truy vấn ~c_i,k_i~ là ~pre[c_i]+pre\left[\dfrac{c_i}{k_i+1}\right]~.
Code mẫu
//TrungNotChung #include <bits/stdc++.h> #define pii pair<int , int> #define fi first #define se second #define BIT(x,i) (1&((x)>>(i))) #define MASK(x) (1LL<<(x)) #define CNT(x) __builtin_popcountll(x) #define task "tnc" using namespace std; const int N = (int)1e6+228; int n, q, p[N]; long long sum[N]; long long getSum(int l, int r) { if(l > r) return 0; return sum[r] - sum[l-1]; } void solve() { cin >> n >> q; for(int i=1; i<=n; ++i) cin >> p[i]; sort(p+1, p+n+1, greater<int>()); for(int i=1; i<=n; ++i) sum[i] = sum[i-1] + p[i]; while(q--) { int x, k; cin >> x >> k; int h = x / (k+1); long long res = getSum(1, h) * 2 + getSum(h+1, x); cout << res << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen(task".inp" , "r" , stdin); //freopen(task".out" , "w" , stdout); solve(); return 0; }
Comments