Submission #1168365


Source Code Expand

#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 5050;
int N, K;
int a[MAX];

bool check(int idx) {   //不必要ならばtrue
    LL sum = a[idx];
    int moveIdx = idx + 1;
    while (sum < K && idx < N) {
        sum += a[moveIdx++];
    }
    //if (sum < K) return true;
    return sum - a[idx] >= K;
}

int main(void) {
    scanf("%d%d", &N, &K);
    REP(i, N) {
        scanf("%d", a + i);
    }
    sort(a, a + N + 1);
    if (accumulate(a, a + N + 1, 0ll) < K) {
        cout << N << endl;
        return 0;
    }
    int high = N, low = 0;
    while (high - low > 1) {
        const int mid = (high + low) / 2;
        (check(mid) ? low : high) = mid;
    }
    cout << low << endl;
}

Submission Info

Submission Time
Task D - No Need
User sekiya9311
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2459 Byte
Status WA
Exec Time 2 ms
Memory 384 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:78:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &K);
                          ^
./Main.cpp:80:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", a + i);
                           ^

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 0 / 300 0 / 300
Status
AC × 3
AC × 18
WA × 8
AC × 34
WA × 17
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
Subtask 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt, 2_041.txt, 2_042.txt, 2_043.txt, 2_044.txt, 2_045.txt, 2_046.txt, 2_047.txt, 2_048.txt, 2_049.txt, 2_050.txt
Case Name Status Exec Time Memory
0_000.txt AC 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 1 ms 256 KB
1_004.txt AC 1 ms 256 KB
1_005.txt AC 1 ms 256 KB
1_006.txt AC 1 ms 256 KB
1_007.txt WA 1 ms 256 KB
1_008.txt WA 1 ms 256 KB
1_009.txt AC 1 ms 256 KB
1_010.txt AC 1 ms 256 KB
1_011.txt AC 1 ms 256 KB
1_012.txt AC 1 ms 256 KB
1_013.txt AC 1 ms 256 KB
1_014.txt AC 1 ms 256 KB
1_015.txt WA 1 ms 256 KB
1_016.txt AC 1 ms 256 KB
1_017.txt WA 1 ms 256 KB
1_018.txt AC 1 ms 256 KB
1_019.txt AC 1 ms 256 KB
1_020.txt WA 1 ms 256 KB
1_021.txt WA 1 ms 256 KB
1_022.txt WA 1 ms 256 KB
1_023.txt WA 1 ms 256 KB
1_024.txt AC 1 ms 256 KB
1_025.txt AC 1 ms 256 KB
2_026.txt AC 2 ms 384 KB
2_027.txt AC 1 ms 256 KB
2_028.txt WA 1 ms 256 KB
2_029.txt WA 2 ms 256 KB
2_030.txt AC 2 ms 256 KB
2_031.txt AC 2 ms 256 KB
2_032.txt AC 2 ms 256 KB
2_033.txt AC 2 ms 256 KB
2_034.txt AC 2 ms 256 KB
2_035.txt AC 2 ms 256 KB
2_036.txt WA 2 ms 256 KB
2_037.txt AC 1 ms 256 KB
2_038.txt WA 1 ms 256 KB
2_039.txt AC 1 ms 256 KB
2_040.txt AC 2 ms 256 KB
2_041.txt WA 2 ms 256 KB
2_042.txt WA 2 ms 256 KB
2_043.txt WA 2 ms 256 KB
2_044.txt WA 2 ms 256 KB
2_045.txt WA 2 ms 256 KB
2_046.txt AC 2 ms 256 KB
2_047.txt AC 2 ms 256 KB
2_048.txt AC 2 ms 256 KB
2_049.txt AC 2 ms 256 KB
2_050.txt AC 2 ms 256 KB