Ads Proposal
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 2127 Accepted Submission(s): 707
Your task is to help Baidu to design this little toolkit.
For each test case, the first line contains three integers N, M and Q, denoting the number customer, the number of advertisement instances and the number of queries. (N <= 100000, M <= 500000, Q <= 100000)
Then M lines follow, each line contains three numbers, U, C and L, indicating the owner of this advertisement, the clicks for this advertisement and the length. (1 <= U <= N, 0 <= C, L <= 1000000000)
Finally Q lines come. Each line contains only one integer k, representing the query for top k clicking advertisements for each customer.
現給Q次查詢,輸出每個客戶點擊量前K大的廣告長度之和
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#define Mod 1000007
using namespace std;
typedef long long ll;
const int N = 100010;
int n,m,q;
struct node {
ll c,l;
int id;
} a[N*5];
ll sk[N*5];
bool cmp(node a,node b) {
return a.id<b.id||(a.id==b.id&&a.c>b.c);
}
int main() {
// freopen("test.in","r",stdin);
int t,ca=1;
cin>>t;
while(t--) {
scanf("%d%d%d",&n,&m,&q);
for(int i=0; i<m; i++) {
scanf("%d%I64d%I64d",&a[i].id,&a[i].c,&a[i].l);
}
sort(a,a+m,cmp);
memset(sk,0,(m+2)*sizeof(sk[0]));///初始化沒有限制會TLE
int o=1;
sk[o++]+=a[0].l;
for(int i=1; i<m; i++) {
if(a[i].id!=a[i-1].id) {
o=1;
}
sk[o++]+=a[i].l;
}
for(int i=1; i<=m; i++)
sk[i]+=sk[i-1];
printf("Case #%d:\n",ca++);
int k;
while(q--) {
scanf("%d",&k);
if(k>m)k=m;
printf("%I64d\n",sk[k]);
}
}
return 0;
}