Accepted
Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ll n, a = 0, b = 0;
string s, t;
cin >> s >> n;
for (int i = 0; i < s.size(); i++){
if (s[i] == '+') {
if (a == 0) a = stoi(t);
else if (b == 0) b = stoi(t);
t = "";
} else {
t += s[i];
}
}
ll ans = (n * (2LL * a + (n - 1) * (b - a))) / 2;
cout << ans;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1231 Busy Friend
- Contest
- Testing - Intra LU Programming contest 25
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-08-31 06:26:45
- Judged At
- 2025-08-31 06:26:45
- Judged By
- Score
- 100
- Total Time
- 1ms
- Peak Memory
- 536.0 KiB