QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#719073 | #9529. Farm Management | tea | WA | 31ms | 12532kb | C++17 | 2.4kb | 2024-11-06 22:19:23 | 2024-11-06 22:19:24 |
Judging History
answer
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define st first
#define nd second
#define PII pair<ll, ll>
#define D(x, y) cout << x << "=" << y << endl;
#define fcout(x, n) cout << fixed << setprecision(x) << n << endl;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
// #define int long long
// #define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f;
const int N = 1e6 + 10;
const int M = 1e9+7;
inline ll read()
{
ll x = 0;
bool f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = 0;
for (; isdigit(c); c = getchar())
x = (x << 3) + (x << 1) + c - '0';
return f ? x : 0 - x;
}
inline void out(ll x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
out(x / 10);
putchar(x % 10 + '0');
}
// __int128 rd()
// {
// char arr[30];
// __int128 res = 0;
// scanf("%s", arr);
// for (int i = 1; i <= strlen(arr); i++)
// {
// res *= 10;
// res += arr[i]-'0';
// }
// return res;
// }
// void pt(__int128 num)
// {
// if (num > 9) pt(num / 10);
// putchar(num % 10 + '0');
// }
ll n, m;
class P
{public:
ll w,l,r;
}p[N];
bool cmp(P a,P b)
{
return a.w>b.w;
}
ll sums[N]={0},sumt[N]={0};
void solve()
{
cin>>n>>m;
ll lt=0,ls=0;
rep(i,1,n+1)
{
cin>>p[i].w>>p[i].l>>p[i].r;
lt+=p[i].l;ls+=p[i].l*p[i].w;
}
ll ans=ls;
if(lt==m) return cout<<ans<<endl,void();
sort(p+1,p+n+1,cmp);
sums[0]=sumt[0]=0;
rep(i,1,n+1)
{
sums[i]=sums[i-1]+p[i].w*(p[i].r-p[i].l);
sumt[i]=sumt[i-1]+p[i].r-p[i].l;
}
rep(i,1,n+1)
{
ll dt=p[i].l+m-lt;
if(sumt[i-1]<=dt)
{
ans=max(ans,ls+sums[i-1]+p[i].w*(dt-sumt[i-1]-p[i].l));
continue;
}
auto t=upper_bound(sumt,sumt+i,dt)-sumt;
ans=max(ans,ls+sums[t-1]+(dt-sumt[t-1])*p[t].w-p[i].w*p[i].l);
}
cout<<ans<<endl;
}
signed main()
{
IOS
// freopen("../.vscode/io/in.txt","r",stdin),freopen("../.vscode/io/out.txt","w",stdout);
ll T = 1;
// cin >> T;
while (T--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7656kb
input:
5 17 2 3 4 6 1 5 8 2 4 4 3 3 7 5 5
output:
109
result:
ok single line: '109'
Test #2:
score: 0
Accepted
time: 0ms
memory: 7812kb
input:
12 62 503792 9 10 607358 1 3 600501 10 10 33249 4 4 774438 6 6 197692 3 6 495807 8 8 790225 5 9 77272 3 8 494819 4 9 894779 3 9 306279 5 6
output:
35204500
result:
ok single line: '35204500'
Test #3:
score: 0
Accepted
time: 2ms
memory: 7748kb
input:
15 32 835418 2 3 178262 1 3 527643 2 2 519710 1 1 774544 3 3 82312 1 1 808199 1 1 809396 1 3 255882 1 3 80467 1 3 874973 1 3 813965 1 2 198275 1 2 152356 1 3 802055 1 1
output:
22000255
result:
ok single line: '22000255'
Test #4:
score: 0
Accepted
time: 2ms
memory: 7676kb
input:
13 20 526447 1 1 807398 2 2 4167 1 2 944031 2 2 830685 2 2 394251 1 2 505011 1 2 968848 1 1 58170 1 3 32504 1 1 792273 3 3 196120 1 2 714507 1 1
output:
12878768
result:
ok single line: '12878768'
Test #5:
score: 0
Accepted
time: 1ms
memory: 7648kb
input:
13 32 582584 1 3 335440 3 3 971984 1 2 864169 1 2 528515 1 1 382399 1 2 459855 1 2 406909 2 3 66780 2 3 885118 3 3 434844 1 2 93331 1 3 502509 1 3
output:
22065034
result:
ok single line: '22065034'
Test #6:
score: 0
Accepted
time: 1ms
memory: 7708kb
input:
12 77 30244 1 7 518214 3 8 486001 8 9 152634 2 3 180255 3 4 791887 1 6 635820 2 9 881171 3 5 337905 3 8 683182 5 5 300786 3 6 339094 7 9
output:
50453764
result:
ok single line: '50453764'
Test #7:
score: 0
Accepted
time: 2ms
memory: 7708kb
input:
10 3923726 826284 215861 638800 471693 146746 886003 140800 532315 684546 673434 604071 814259 170671 299465 525449 104262 689547 855391 215333 591975 803421 795321 31606 984783 103838 361911 601318 145693 450227 686945
output:
1597735409747
result:
ok single line: '1597735409747'
Test #8:
score: 0
Accepted
time: 31ms
memory: 12532kb
input:
100000 16648414311 252800 55607 195981 157144 548469 789695 643048 2 2 907957 3 3 32532 231618 316365 194428 227513 762023 4231 393553 699179 898052 3 5 507551 3 5 747498 1 4 857939 9 9 440056 764429 796585 495571 117772 838593 4059 551203 870687 60877 597981 770178 593237 4 10 438147 218335 370780 ...
output:
4148641232436282
result:
ok single line: '4148641232436282'
Test #9:
score: -100
Wrong Answer
time: 15ms
memory: 7744kb
input:
100000 14997174848 996832 2 5 193379 411081 976749 339827 553492 639067 127364 131886 237768 615192 3 9 417612 599185 637969 812326 2 5 22605 80976 90557 350917 119223 755129 807528 7 8 165108 327186 793786 126946 530792 700713 246467 387234 557026 286888 485816 869662 398882 73798 458939 651741 3 9...
output:
3763428215464406
result:
wrong answer 1st lines differ - expected: '3763949202789374', found: '3763428215464406'