提出 #68374759
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
// Typedef
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<ll, ll> mll;
typedef set<int> si;
// Macros
#define PB push_back
#define IN insert
#define all(x) x.begin(), x.end()
#define trav(i, a) for (auto &i : a)
#define GCD __gcd
#define MP make_pair
#define F first
#define S second
#define endl '\n'
#define sz(x) (ll)x.size()
#define LB lower_bound
#define UB upper_bound
#define DEBUG(i) cout << "DEBUG " << i << "\n";
#define CASE(i) cout << "Case " << i << ": ";
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define REV(i, a, b) for (int i = a; i >= b; i--)
#define GT(x) greater<x>()
#define setpre(n) fixed << setprecision(n)
#define print(x) for(auto &i : x) cout << i << " " ; cout '\n'
#define SZ(x) x.size()
#define LEN(s) s.length()
#define MEM(arr, val) memset(arr, val, sizeof(arr));
// Functions
template <typename T>
void pv(vector<T> &a){
for (T u : a) cout << u << ' ';
cout << '\n';
}
template <typename T>
void pv2(vector<vector<T>> &a){
for (auto &aa : a) {
pv(aa);
}
}
// Constants
const ll MOD7 = 1e9 + 7;
const ll MOD9 = 998244353;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
// Custom Functions
void fast() {
ios::sync_with_stdio(false);
cin.tie(0);
}
ull LCM(ull a, ull b){
return (a * b) / GCD(a, b);
}
// Custom Comparator
bool cmp(const pair<char, pair<int, int>>& x, const pair<char, pair<int, int>>& y){
return x.F < y.F;
}
// Extra Info
// INT_MAX for max value... min_diff = INT_MAX
// INT_MIN for min value... max_sum = INT_MIN --> for Kadane's Algorithm
// Global Variables
// const int LMT = 1000 + 10;
// vector<vector<int>> adj(LMT);
// vector<bool> vis(LMT, 0);
// vi ans;
// bool isOk = 0;
void solve(ll tc){
ll n, q;
cin >> n >> q;
vll v(n + 1, 0);
REP(i, 1, n) cin >> v[i];
sort(all(v));
// pv(v);
vll pre(n + 1, 0);
REP(i, 1, n) pre[i] = pre[i - 1] + v[i];
// pv(pre);
ll mx = *max_element(all(v));
while (q--){
ll x;
cin >> x;
if (x > mx){
cout << -1 << '\n';
continue;
}
ll ind = LB(all(v), x - 1) - v.begin() - 1;
ind = max(0ll, ind);
// DEBUG(ind)
ll sum = pre[ind];
sum += (x - 1) * (n - ind) + 1;
cout << sum << '\n';
}
}
int main(void){
fast();
// precal();
// freopen("fenceplan.in", "r", stdin);
// freopen("fenceplan.out", "w", stdout);
ll t = 1;
int i = 1;
// cin >> t;
// for (ll i = 1; i <= t; i++)
solve(i);
}
提出情報
| 提出日時 |
|
| 問題 |
C - Flush |
| ユーザ |
priashisg |
| 言語 |
C++ 17 (gcc 12.2) |
| 得点 |
350 |
| コード長 |
3184 Byte |
| 結果 |
AC |
| 実行時間 |
105 ms |
| メモリ |
9048 KiB |
コンパイルエラー
Main.cpp: In function ‘void solve(ll)’:
Main.cpp:99:15: warning: unused parameter ‘tc’ [-Wunused-parameter]
99 | void solve(ll tc){
| ~~~^~
Main.cpp: In function ‘int main()’:
Main.cpp:150:8: warning: unused variable ‘t’ [-Wunused-variable]
150 | ll t = 1;
| ^
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
350 / 350 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00-sample-01.txt, 00-sample-02.txt |
| All |
00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00-sample-01.txt |
AC |
1 ms |
3556 KiB |
| 00-sample-02.txt |
AC |
1 ms |
3408 KiB |
| 01-01.txt |
AC |
4 ms |
3548 KiB |
| 01-02.txt |
AC |
4 ms |
3468 KiB |
| 01-03.txt |
AC |
5 ms |
3384 KiB |
| 01-04.txt |
AC |
105 ms |
8912 KiB |
| 01-05.txt |
AC |
45 ms |
7732 KiB |
| 01-06.txt |
AC |
62 ms |
8848 KiB |
| 01-07.txt |
AC |
76 ms |
9048 KiB |
| 01-08.txt |
AC |
69 ms |
8828 KiB |
| 01-09.txt |
AC |
101 ms |
8308 KiB |