标签:int str cto least sam pow ice nta ast
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2023 Accepted Submission(s): 738
1 #include"bits/stdc++.h" 2 3 #define db double 4 #define ll long long 5 #define vl vector<ll> 6 #define ci(x) scanf("%d",&x) 7 #define cd(x) scanf("%lf",&x) 8 #define cl(x) scanf("%lld",&x) 9 #define pi(x) printf("%d\n",x) 10 #define pd(x) printf("%f\n",x) 11 #define pl(x) printf("%lld\n",x) 12 #define rep(i, a, n) for (int i=a;i<n;i++) 13 #define per(i, a, n) for (int i=n-1;i>=a;i--) 14 #define fi first 15 #define se second 16 using namespace std; 17 typedef pair<int, int> pii; 18 const int N = 1e5 + 5; 19 const int mod = 1e9 + 5; 20 const int MOD = 992353; 21 const db PI = acos(-1.0); 22 const db eps = 1e-10; 23 const int inf = 0x3f3f3f3f; 24 const ll INF = 0x3fffffffffffffff; 25 int n; 26 struct P { 27 int x, id; 28 P(int a, int b) : x(a), id(b) {}; 29 bool operator<(const P &a) const { 30 if (x == a.x) return id < a.id;//反向重载 31 return x > a.x; 32 } 33 }; 34 35 int main() { 36 int T; 37 ci(T); 38 while (T--) { 39 ci(n); 40 priority_queue<P> q; 41 ll ans = 0, cnt = 0; 42 for (int i = 0, x; i < n; i++) { 43 ci(x); 44 if (!q.empty() && q.top().x < x) { 45 P tmp = q.top();q.pop(); 46 ans += x - tmp.x; 47 if (!tmp.id) cnt++; 48 q.push(P(x, 1));//以x的价格卖出过,以后可能还会以更高的价格卖 49 } 50 q.push(P(x, 0));//要以x的价格买入 51 } 52 printf("%lld %lld\n", ans, 2 * cnt); 53 } 54 return 0; 55 }
标签:int str cto least sam pow ice nta ast
原文地址:https://www.cnblogs.com/mj-liylho/p/9567146.html