QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#398404 | #4233. Reset | MHo2005 | WA | 1ms | 3816kb | C++20 | 1.4kb | 2024-04-25 11:44:13 | 2024-04-25 11:44:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=201000;
int t[N],d[N],n,c,cnt[N];
vector<array<int,3>> ev;
bool check(ll md) {
ll tots=0;
rep(i,0,n) {
cnt[i]=0;
tots+=t[i];
}
ll cc=0;
for (auto [d,t,id]:ev) {
ll mt=min((ll)t,md-cnt[id]);
cnt[id]+=mt;
cc+=mt;
tots-=d*mt;
}
int last=0;
rep(i,0,n) if (cnt[i]==md) {
last++;
}
cc=max(cc-(__int128_t)(md-1)*c,(__int128_t)0);
return tots<=c-cc;
}
int main() {
scanf("%d%d",&n,&c);
ll l=0,r=0;
rep(i,0,n) {
scanf("%d%d",t+i,d+i);
r+=(t[i]+d[i]-1)/d[i];
}
rep(i,0,n) {
ev.pb({d[i],t[i]/d[i],i});
if (t[i]%d[i]) ev.pb({t[i]%d[i],1,i});
}
while (l+1<r) {
ll md=(l+r)/2;
if (check(md)) r=md; else l=md;
}
printf("%lld\n",l);
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3816kb
input:
3 5 17 5 5 2 15 4
output:
2
result:
wrong answer 1st lines differ - expected: '3', found: '2'