2 条题解
-
2
该死的oj最后卡死让我没改换long long痛失100!
using namespace std; const int M=1e6+1; long long ans,L,N,vs,vj,tim; struct node { int t,v; } a[M]; bool cmp(node a,node b) { return a.v>b.v; } int main() { cin>>L>>N>>vs>>vj; for(int i=1; i<=N; i++) { int p; cin>>p>>a[i].v; a[i].t=p*(vs-vj); } sort(a+1,a+N+1,cmp); for(int i=1; i<=N; i++) { if(tim<=a[i].t) { ans+=(a[i].t-tim)*a[i].v; tim=a[i].t; } } cout<<ans; }
-
1
考虑贪心。
按照 从大到小将每个休息点排序,先吃最大的,一直吃到不能再吃,然后再往后面吃。
l, n, v1, v2 = map(int, input().split()) a = [] for i in range(n): start, value = map(int, input().split()) a.append((start, value)) a.sort(key=lambda x: -x[1]) ans = 0 a2 = 0 for start, value in a: if start * v2 + a2 <= start * v1: ans += (start * v1 - start * v2 - a2) * value a2 = start * v1 - start * v2 print(ans)
- 1
信息
- ID
- 987
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 258
- 已通过
- 32
- 上传者