답안 #793719

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793719 2023-07-26T05:56:01 Z 반딧불(#10057) Triangle Collection (CCO23_day2problem3) C++17
0 / 25
315 ms 396 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, q;
ll arr[200002];
ll val[200002];

void solve(){
    set<int> st;
    ll ans = 0;
    for(int i=1; i<=n; i++){
        val[i] = arr[i];
        if(val[i]) st.insert(i);
    }
    for(int i=1; i<=n; i++){
        while(val[i] >= 2){
            if(st.empty() || *st.begin() >= 2*i ||
               (*st.begin() == i && val[i] == 2 && ((int)st.size() == 1 || *next(st.begin()) >= 2*i))) break;
            int x = i, y = *st.begin();
            if(y==i && val[i]==2) y = *next(st.begin());
            int k;
            if(x==y) k = val[x] / 3;
            else k = min(val[x] / 2, val[y]);
            ans += k;
            val[x] -= k*2, val[y] -= k;
            if(!val[x]) st.erase(x);
            if(!val[y]) st.erase(y);
        }
    }
    printf("%lld\n", ans);
}

int main(){
    scanf("%d %d", &n, &q);
    for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
    while(q--){
        int x; ll v;
        scanf("%d %lld", &x, &v);
        arr[x] += v;
        solve();
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:38:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%d %lld", &x, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 7 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 7 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 315 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 261 ms 388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 7 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -