原题:https://ac.nowcoder.com/acm/problem/211539
对于这题因为不管怎么取都肯定能取到前y大的值所以我们只需要前缀和记录下然后在暴力求解即可
#include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> #include <vector> #include <string> #include <cmath> #include <map> #include <deque> #include <queue> #include <list> #include <set> #include <stack> #include <random> #include <string> #include <cmath> #include <ctime> #include <bitset> #include <iostream> #include <unordered_map> #define ll long long #define eps 1e-6 #define inf 0x3f3f3f #define db long double //freopen("input.in", "r", stdin); //freopen("ouput.out", "w", stdout); const int N=1e5+10; using namespace std; ll a[N],qz[N]; int n; int cmp(int a,int b){ return a>b; } int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; ll ans=0; int x,y;cin>>x>>y; sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++){ qz[i]+=qz[i-1]+a[i]; } for(int i=1;i<=x;i++){ for(int j=1;j<=y;j++){ ans+=qz[i*j]; } } cout<<ans<<endl; return 0; }