結果

問題 No.2424 Josouzai
ユーザー kaityo_17kaityo_17
提出日時 2023-08-18 21:28:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 2,760 bytes
コンパイル時間 2,854 ms
コンパイル使用メモリ 251,636 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 03:18:46
合計ジャッジ時間 5,805 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 30 ms
5,376 KB
testcase_05 AC 99 ms
5,376 KB
testcase_06 AC 93 ms
5,376 KB
testcase_07 AC 93 ms
5,376 KB
testcase_08 AC 98 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 24 ms
5,376 KB
testcase_11 AC 66 ms
5,376 KB
testcase_12 AC 49 ms
5,376 KB
testcase_13 AC 30 ms
5,376 KB
testcase_14 AC 53 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 86 ms
5,376 KB
testcase_17 AC 24 ms
5,376 KB
testcase_18 AC 27 ms
5,376 KB
testcase_19 AC 46 ms
5,376 KB
testcase_20 AC 87 ms
5,376 KB
testcase_21 AC 67 ms
5,376 KB
testcase_22 AC 30 ms
5,376 KB
testcase_23 AC 36 ms
5,376 KB
testcase_24 AC 17 ms
5,376 KB
testcase_25 AC 92 ms
5,376 KB
testcase_26 AC 67 ms
5,376 KB
testcase_27 AC 96 ms
5,376 KB
testcase_28 AC 81 ms
5,376 KB
testcase_29 AC 73 ms
5,376 KB
testcase_30 AC 18 ms
5,376 KB
testcase_31 AC 43 ms
5,376 KB
testcase_32 AC 94 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,n) for(int i = a; i < n; i++)
#define yes (cout << "Yes" << endl)
#define YES (cout << "YES" << endl)
#define no (cout << "No" << endl)
#define NO (cout << "NO" << endl)
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define all(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vd = vector<double>;
using vl = vector<long long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using Graph = vector<vector<int>>;
const int mod = 998244353;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;
const string abc = "abcdefghijklmnopqrstuvwxyz";
int dight_sum(int t) {
    int ans = 0;
    while(t >= 10) {
        ans += t % 10;
        t /= 10;
    }
    ans += t;
    return ans;
}
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}
ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}
struct unionfind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    unionfind (int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
long long factorial(long long k) {
    ll ans = 1;
    rep(i,1,k + 1) {
        ans *= i;
    }
    return ans;
}

int main () {
    cout << fixed << setprecision(10);
    int n,k;
    cin >> n >> k;
    int ans = 0;
    int a[n];
    rep(i,0,n) {
        cin >> a[i];
    }

    sort(a,a + n);
    rep(i,0,n) {
        if(k >= a[i]) {
            k -= a[i];
            ans++;
        }
        else{
            cout << ans << " " << k << endl;
            return 0;
        }
    }
    cout << ans << " " << k <<  endl;
}
0