QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85221 | #4233. Reset | TheOneYouWant | WA | 2ms | 3532kb | C++20 | 2.3kb | 2023-03-07 11:26:47 | 2023-03-07 11:26:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define int long long int
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define ln '\n'
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
out<<"{ ";
for(auto &x : c) out<<x<<" ";
out<<"}"; return out;
}
const int MOD = 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, c;
vector<pii> tasks;
bool check(int val){
priority_queue<pii> q;
rep(i, 0, tasks.size()){
q.push(tasks[i]);
}
// max d, then t
int consumed = 0;
// consumed should be <= val for each
int final = 0;
// final should be <= c at the end
while(!q.empty()){
auto t = q.top();
q.pop();
assert(t.first <= t.second); // should always hold
assert(t.first != 0);
int to_almost_fin = t.second / t.first; // as much as we can remove
to_almost_fin = min(to_almost_fin, val+1); // only once per iteration
// to_almost_fin = min(to_almost_fin, c * (val - consumed); // how much quota is left
consumed += to_almost_fin;
t.second -= to_almost_fin * t.first; // updated time left
assert(t.second >= 0);
if(t.second==0) continue;
// t.second is the remaining time
if(to_almost_fin == val+1){
// we removed all the times we could, in the past
// so now can only do future work
final += 1; // spend 1 second to research
t.second -= min(t.first, t.second);
final += t.second; // just run now
continue;
}
q.push({min(t.first, t.second), t.second});
}
final += max(0ll, consumed - c * val);
if(final > c) return 0;
return 1;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin >> n >> c;
rep(i, 0, n){
int t, d;
cin >> t >> d;
tasks.push_back({d,t});
}
int l = 0, r = (1e17+c-1)/c;
while(l<r){
int mid = (l+r)/2;
if(check(mid)){
r = mid;
}
else{
l = mid+1;
}
}
// cout << check(4) << endl;
// assert(l==r);
cout << l << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3532kb
input:
3 5 17 5 5 2 15 4
output:
2
result:
wrong answer 1st lines differ - expected: '3', found: '2'