Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
来源:互联网 发布:美工在线培训 编辑:程序博客网 时间:2024/06/08 17:59
都选最优的,最多会多出一盒饼,然后减去最少的就行了
#include <bits\stdc++.h>using namespace std;#define pb push_back#define mp make_pairconst int maxn=1e5+9;vector< pair<long long ,long long> >aa,bb;bool cmp(pair<long long ,long long> a, pair<long long ,long long> b){ return a.first<b.first;}long long s[maxn],a[maxn],b[maxn];int main(){ //freopen("test.in","r",stdin); int n;long long s1;long long len1,len2,ans,ans1,ans2,len;len=len1=len2=0;ans1=ans2=0;scanf("%d%I64d",&n,&s1);for(int i=1;i<=n;i++){ scanf("%I64d%I64d%I64d",&s[i],&a[i],&b[i]); len+=s[i]; if(a[i]<b[i]) { len1+=s[i]; ans1+=b[i]*s[i]; aa.pb(mp(b[i]-a[i],s[i])); } else { len2+=s[i]; ans2+=a[i]*s[i]; bb.pb(mp(a[i]-b[i],s[i])); }}if((len/s1+(len%s1==0?0:1))>=((len2/s1+(len2%s1==0?0:1))+(len1/s1+(len1%s1==0?0:1))))//这个判断少加了点东西,终测挂了,挂我锁他了,结束之前就发现错误了 printf("%I64d\n",ans1+ans2);else{ len1=len1%s1; len2=len2%s1; len1=min(len1,s1-len2); len2=min(len2,s1-len1); long long tmp1,tmp2; tmp1=tmp2=0; long long sum1=0; long long sum2=0; sort(aa.begin(),aa.end(),cmp); sort(bb.begin(),bb.end(),cmp); for(int i=0;i<aa.size();i++) { if(tmp1+aa[i].second<len1) { tmp1+=aa[i].second; sum1+=aa[i].second*aa[i].first; } else { sum1+=(len1-tmp1)*aa[i].first; break; } } for(int i=0;i<bb.size();i++) { if(tmp2+bb[i].second<len2) { tmp2+=bb[i].second; sum2+=bb[i].second*bb[i].first; } else { sum2+=(len2-tmp2)*bb[i].first; break; } } // printf("%lld\n",ans1+ans2); ans=ans1+ans2-min(sum1,sum2); printf("%I64d\n",ans);} return 0;}
阅读全文
0 0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- Codeforces MemSQL start[c]up Round 1
- MemSQL Start[c]UP 2.0 Round 2
- MemSQL Start[c]UP 2.0 - Round 2
- Codeforces Round MemSQL start[c]up Round 1
- CodeForces MemSQL start[c]up Round 1 A题
- codeforces MemSQL Start[c]UP 2.0 - Round 1 A. Eevee
- Codeforces MemSQL Start[c]UP 2.0 - Round 1
- vue2.0实现引用qrcode.js实现获取改变二维码的样式(2)
- Spring Boot AOP之对请求的参数入参与返回结果进行拦截处理
- for while循环 列表长度变化
- Linux基础
- 一次极其痛苦troubleshooting:ORA-04061: existing state of has been invalidated
- Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0
- 数组的复制
- Java多线程问题总结
- multiprocess模块使用进程池调用apply_async()提交的函数及回调函数不执行问题
- Vue2.0实现调用摄像头进行拍照功能以及图片上传功能引用exif.js(2)
- IBM --Java 实习生面试题
- 关于 GET和POST请求的区别
- 简单通俗解释内外网IP与端口映射
- 浅析js事件冒泡机制