标签:++ class 发展 map bsp get 表示 stack info
时间限制:1 Sec 内存限制:128 MiB
提交:221
答案正确:59
输出对女朋友的最小刺激值;结果占一行。
2 4 2 20 1 10 1 30 2 40 2 6 2 20 1 10 1 30 2 40 2 50 3 60 3
30 100
// copy的代码不很懂 #include <iostream> #include <vector> #include <queue> #include <cstdio> #include <algorithm> using namespace std; priority_queue <int, vector<int>, greater<int> > Q;// int型降序优先队列 vector <int> a[1000100]; int main() { int T; cin >> T; while(T--) { int n, m; cin >> n >> m; int e, f, Max = 0; long long ans = 0; for(int i=1; i<=n; i++) { scanf("%d %d",&e, &f); if(f > Max) Max = f; ans += e; a[f].push_back(e); } int times = 0; for(int t=1; t<=m; t++) { times ++; int len = a[t].size(); if(0 == len) continue; if(len <= times) { times -= len; for(int j=0; j<len; j++) { Q.push( a[t][j] ); } } else { sort(a[t].begin(), a[t].end()); for(int k=1; k<=times; k++) { Q.push(a[t][len-k]); } for(int k = times+1; k<=len; k++) { if(a[t][len-k] > Q.top()) { Q.pop(); Q.push(a[t][len-k]); } else break; } times = 0; } a[t].clear(); } for(int t=m+1; t<=Max; t++) { int len = a[t].size(); if(0 == len) continue; if(len <= times) { times -= len; for(int j=0; j<len; j++) { Q.push( a[t][j] ); } } else { sort(a[t].begin(), a[t].end()); for(int k=1; k<=times; k++) { Q.push(a[t][len-k]); } for(int k = times+1; k<=len; k++) { if(a[t][len-k] > Q.top()) { Q.pop(); Q.push(a[t][len-k]); } else break; } times = 0; } a[t].clear(); } while(!Q.empty()) { ans -= Q.top(); Q.pop(); } cout << ans << endl; } return 0; }
#include<iostream> #include<cstring> #include<queue> #include<cstdio> #include<stack> #include<set> #include<map> #include<cmath> #include<ctime> #include<time.h> #include<algorithm> #include<bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define debug puts("debug") #define LL unsigned long long #define pii pair<int,int> #define eps 1e-10 #define inf 0x3f3f3f3f LL MOD=1e9+7; struct node{ int a,b; bool operator<(const node& tmp)const{ return a<tmp.a; } }P[100010]; bool cmpb(node A,node B){ return A.b>B.b; } priority_queue<node>q; int main() { LL t,n,m,i,j,k; cin>>t; while(t--){ while(!q.empty()) q.pop(); scanf("%lld%lld",&n,&m); LL sum=0,ans=0; for(i=1;i<=n;++i){ scanf("%d%d",&P[i].a,&P[i].b); sum+=P[i].a; } sort(P+1,P+1+n,cmpb); for(i=m,j=1;i>=1;--i){ while(j<=n&&P[j].b>=i) q.push(P[j++]); if(!q.empty()){ ans+=q.top().a; q.pop(); } } cout<<sum-ans<<endl; } return 0; }
标签:++ class 发展 map bsp get 表示 stack info
原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9065261.html