답안 #810705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
810705 2023-08-06T14:21:14 Z Username4132 Akcija (COCI21_akcija) C++14
10 / 110
138 ms 16828 KB
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using pil = pair<int, ll>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define PB push_back
#define F first
#define S second
#define MP make_pair

const int MAXN = 20;
int n, k, we[MAXN], tim[MAXN], arr[MAXN];
vector<pil> ans;

void solve(int mask){
    int cnt=0;
    ll sum=0;
    forn(i, n) arr[i]=0;
    while(mask){
        int x = __builtin_ctz(mask);
        mask^=(1<<x);
        ++cnt;
        sum+=we[x];
        arr[tim[x]]++;
    }
    bool flag=true;
    forn(i, n-1) arr[i+1]+=arr[i];
    forn(i, n) flag&=(arr[i]<=(i+1));
    if(flag) ans.PB({cnt, sum});
}

int main(){
    scanf("%d %d", &n, &k);
    forn(i, n){
        scanf("%d %d", &we[i], &tim[i]);
        --tim[i];
    }
    forn(i, (1<<n)) solve(i);
    sort(ans.begin(), ans.end(), [](pil a, pil b){
        return MP(-a.F, a.S) < MP(-b.F, b.S);
    });
    forn(i, k) printf("%d %lld\n", ans[i].F, ans[i].S);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d %d", &we[i], &tim[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 8628 KB Output is correct
2 Correct 138 ms 16828 KB Output is correct
3 Correct 34 ms 4548 KB Output is correct
4 Correct 29 ms 2444 KB Output is correct
5 Correct 132 ms 16728 KB Output is correct
6 Correct 11 ms 304 KB Output is correct
7 Correct 48 ms 940 KB Output is correct
8 Correct 11 ms 484 KB Output is correct
9 Correct 12 ms 340 KB Output is correct
10 Correct 22 ms 296 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 54 ms 4484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -