QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#368083 | #3998. The Profiteer | Graphcity | WA | 1ms | 5804kb | C++20 | 1.3kb | 2024-03-26 19:59:32 | 2024-03-26 19:59:32 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=2e5,inf=1e9+7;
int n,m,E,a[Maxn+5],b[Maxn+5],h[Maxn+5],ans[Maxn+5];
vector<vector<int>> v;
inline void Insert(int p)
{
v.push_back(v.back());
For(i,a[p],m) v.back()[i]=max(v.back()[i],v.back()[i-a[p]]+h[p]);
}
inline int Check()
{
ll res=0; For(i,1,m) res+=v.back()[i];
if(res>1ll*m*E) return 1; return 0;
}
inline void dfs(int l,int r,int ql,int qr)
{
if(l>r || ql>qr) return;
int mid=(l+r)>>1,pos=-1;
For(i,l,mid) Insert(i);
Rof(i,qr,max(mid+1,ql))
{
if(Check()) {pos=i; break;}
Insert(i-1);
} if(pos==-1) pos=mid; ans[mid]=pos;
For(i,pos,qr-1) v.pop_back();
dfs(mid+1,r,pos,qr);
For(i,l,mid) v.pop_back();
Rof(i,qr-1,pos) Insert(i);
dfs(l,mid-1,ql,pos);
}
int main()
{
// freopen("1.in","r",stdin);
cin>>n>>m>>E;
For(i,1,n) cin>>h[i]>>a[i]>>b[i];
v.push_back(vector<int>(m+2,0));
For(i,1,n) For(j,b[i],m) v[0][j]=max(v[0][j],v[0][j-b[i]]+h[i]);
int it=n+1; while(!Check() && it) Insert(--it); ans[0]=it;
while(v.size()>1) v.pop_back();
dfs(1,n,1,n+1); ll all=0;
For(i,0,n) all+=(n-max(ans[i],i+1)+1);
cout<<all<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
4 5 3 3 2 4 1 2 3 2 1 2 3 1 3
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5804kb
input:
4 5 4 3 2 4 1 2 3 2 1 2 3 1 3
output:
3
result:
ok single line: '3'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5596kb
input:
4 5 5 3 2 4 1 2 3 2 1 2 3 1 3
output:
3
result:
wrong answer 1st lines differ - expected: '7', found: '3'