标签:sam clear str stc idt testcase pad 解题思路 tca
2 10 3 2 2 2 8 2 5 1 10 4 1 2 2 8 2 5 1 0 10000
18 26
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <vector> #include <queue> #include <stack> #include <cmath> #include <algorithm> #define LL long long using namespace std; const int MAXN = 100000 + 10; int L, N, K; LL x[MAXN]; LL ld[MAXN], rd[MAXN]; vector<LL>l, r; int main() { int T; scanf("%d", &T); while(T--) { scanf("%d%d%d", &L, &N, &K); l.clear(); r.clear(); int pos, num, m = 0; for(int i=1;i<=N;i++) { scanf("%d%d", &pos, &num); for(int i=1;i<=num;i++) x[++m] = (LL)pos; } for(int i=1;i<=m;i++) { if(2 * x[i] < L) l.push_back(x[i]); else r.push_back(L - x[i]); } sort(l.begin(), l.end()); sort(r.begin(), r.end()); int lsz = l.size(), rsz = r.size(); memset(ld, 0, sizeof(ld)); memset(rd, 0, sizeof(rd)); for(int i=0;i<lsz;i++) ld[i + 1] = (i + 1 <= K ? l[i] : ld[i + 1 - K] + l[i]); for(int i=0;i<rsz;i++) rd[i + 1] = (i + 1 <= K ? r[i] : rd[i + 1 - K] + r[i]); LL ans = (ld[lsz] + rd[rsz]) * 2; for(int i=0;i<=lsz&&i<=K;i++) { int p1 = lsz - i; int p2 = max(0, rsz-(K-i)); ans = min(ans, 2*(ld[p1] + rd[p2]) + L); } cout << ans << endl; } return 0; }
HDU 5303 Delicious Apples (2015多校第二场 贪心 + 枚举)
标签:sam clear str stc idt testcase pad 解题思路 tca
原文地址:http://www.cnblogs.com/yutingliuyl/p/6920633.html