训练(training)
50分代码(无能为力)
优先队列
#include<iostream> #include<queue> #define val first #define high second using namespace std; const int M = 1000000; int n,m; priority_queue <pair<int,int> > que;//降序排列 int h[1000010],v[1000010]; int sum[1000010]; int main() { cin >> n >> m; for(int i = 1;i <= n;i ++) { cin >> h[i] >> v[i]; sum[i] = sum[i - 1] + v[i]; } int t1 = 0; int ans; int maxn = 0; for(int k = 1;k <= n;k ++) { int time = m - t1; for(int i = 1;i <= k;i ++) { que.push(make_pair(v[i],h[i] - 1)); } ans = sum[k]; while(time > 0 && (!que.empty())) { pair<int,int> a = que.top(); que.pop(); if(time < a.high) { ans += a.val * time; time = 0; } else { ans += a.val * a.high; time -= a.high; } } t1 ++; if(ans > maxn) { maxn = ans; } while(!que.empty()) { que.pop(); } } cout << maxn; return 0; }