QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#85211#4233. ResetTheOneYouWantWA 2ms3536kbC++202.2kb2023-03-07 11:02:472023-03-07 11:02:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-07 11:02:49]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3536kb
  • [2023-03-07 11:02:47]
  • 提交

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());

ll 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

		int to_almost_fin = t.second / t.first; // as much as we can remove
		to_almost_fin = min(to_almost_fin, val); // 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) || (consumed == c*val)){
			// 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});
	}

	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 = (3e14+c-1)/c;

	while(l<r){
		int mid = (l+r)/2;
		if(check(mid)){
			r = mid;
		}
		else{
			l = mid+1;
		}
	}

	assert(l==r);

	cout << l << endl;


	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3532kb

input:

3 5
17 5
5 2
15 4

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

2 1345
1344 1
10 10

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

1 1000000000
1000000000 1

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

3 2345
333 1
444 2
555 3

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

1 500
1000 2

output:

250

result:

ok single line: '250'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3448kb

input:

1 499
1000 2

output:

250

result:

ok single line: '250'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3528kb

input:

3 2345
3333 5
4444 6
5555 6

output:

646

result:

ok single line: '646'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3500kb

input:

8 6
40 10
40 10
40 10
40 10
40 10
20 5
4 3
5 3

output:

4

result:

ok single line: '4'

Test #9:

score: -100
Wrong Answer
time: 2ms
memory: 3492kb

input:

8 6
40 10
40 10
40 10
40 10
40 10
20 5
7 3
5 3

output:

5

result:

wrong answer 1st lines differ - expected: '4', found: '5'