QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#602581 | #8723. 乘二 | UESTC_OldEastWest# | RE | 0ms | 0kb | C++17 | 1.1kb | 2024-10-01 10:54:23 | 2024-10-01 10:54:23 |
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int mod = 1e9 + 7;
inline int ksm(int x, int p) {
x %= mod;
int ans = 1;
while (p) {
if (p & 1) ans = ans * x % mod;
x = x * x % mod;
p >>= 1;
}
return ans;
}
inline void Solve() {
int n, k; vector<int> a(n + 1);
cin >> n >> k;
priority_queue<int, vector<int>, greater<int>>q;
for (int i = 1; i <= n; i++) cin >> a[i], q.push(a[i]);
while (k) {
int x = q.top();
if (x >= 1e12) break;
q.pop();
q.push(x * 2);
k--;
}
int times = ksm(2, k / n);
for (int i = 1; i <= n; i++) a[i] = q.top() % mod * times % mod, q.pop();
for (int i = 1; i <= k % n; i++) a[i] = a[i] * 2 % mod;
int ans = 0;
for (int i = 1; i <= n; i++) ans = (ans + a[i]) % mod;
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T--) {
Solve();
}
return 0;
}
/*
3 3
7 2 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 3 7 2 1