Skip to content

Commit

Permalink
ABC365C Transportation Expenses
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicfred committed Aug 5, 2024
1 parent 4d0dc6b commit d3fc42e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions atcoder/abc365c_transportation_expenses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Vicfred
// https://atcoder.jp/contests/abc365/tasks/abc365_c
// binary search, sorting
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
long long N, M;
cin >> N >> M;
vector<long long> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
sort(begin(A), end(A));
vector<long long> cummulative(N, 0);
cummulative[0] = A[0];
for (int i = 1; i < N; ++i) {
cummulative[i] = cummulative[i - 1] + A[i];
}
long long L, R;
long long w = A[N - 1];
L = 0;
R = 100000000000LL;
if (cummulative[N - 1] <= M) {
cout << "infinite" << endl;
return 0;
}
while (L < R) {
long long m = (L + R + 1) / 2LL;
long long cost = 0LL;
for (int i = 0; i < N; ++i) {
cost += min(m, A[i]);
}
if (cost > M) {
R = m - 1;
} else {
L = m;
}
}
cout << L << endl;
return 0;
}

0 comments on commit d3fc42e

Please sign in to comment.